Forum Discussion
Joe_Pipitone
Nimbostratus
Jun 05, 2009Redirect - adding elseif
I want to add multiple redirect statements to a single iRule, when a match is found, redirect, else, keep going until i find a match. Can anyone tell me what i am missing here?
when HTTP_REQUEST {
if { ([HTTP::host] eq "domain1.com") } {
HTTP::redirect "http://domain2.com"
} elseif { (HTTP::host] eq "domain3.org") } {
HTTP::redirect "http://domain4.org"
}
}
This is the error the big-ip is giving me:
01070151:3: Rule [Redirect_test] error:
line 4: [parse error: PARSE syntax 132 {syntax error in expression " (HTTP::host] eq "domain3.org") ": variable references require preceding $}] [{ (HTTP::host] eq "domain3.org") }]
- Joe_Pipitone
Nimbostratus
OK, so I did some further reading and found it was best to use a switch statement. - Good approach with the switch! If you were wondering, the second "HTTP::host" was missing the beginning left bracket before it.
- Joe_Pipitone
Nimbostratus
Doh!! Thanks Joe! - Joe_Pipitone
Nimbostratus
Do you know how I can also listen for www.domain1.com as well as domain1.com - both with and without the www? I tried using && and ||, but it was throwing an error with my switch iRule. I have multiple host headers that I would like to redirect. - Colin_Walker_12Historic F5 AccountFor both you'd just use the glob matching, like you already are, and add an asterisk, like so:
when HTTP_REQUEST { set h [HTTP::host] set u [HTTP::uri] switch -glob $h { "*domain1.com" { HTTP::redirect "http://domain2.com" } "*domain3.org" { HTTP::redirect "http://domain4.org" } } }
when HTTP_REQUEST { set h [HTTP::host] set u [HTTP::uri] switch -glob $h { "www.domain1.com" - "domain1.com" { HTTP::redirect "http://domain2.com" } "www.domain3.org" - "domain3.org" { HTTP::redirect "http://domain4.org" } } }
- Joe_Pipitone
Nimbostratus
Thank you!!!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects