Forum Discussion
Trouble with switch statements and multiple http::host and http::uri
I've scripted an iRule in hopes of being able to consolidate multiple rules together. This rule is supposed to check the host, check the uri, and evaluate both, and redirect where needed.
The first host check is working fine (events.oursite.com) and redirects fine, however if I try to enter the second host into my browser, I'm simply not being redirected properly. (adifferentsite.com)
I'm stumped, in the meantime I'm going to try and improve on my syntax. Can anyone point me in the right direction as far as where I may be going wrong? Thank you in advance!
Here's the rule:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"events.oursite.com" {
Check the URI, set to lowercase
switch [string tolower [HTTP::uri]] {
"/eventpage.aspx?event=something08" {
HTTP::redirect "http://redirecteddomain.com"
return
}
}
switch -glob [string tolower [HTTP::host]] {
"adifferentsite.com" {
Check the URI, set to lowercase
switch [string tolower [HTTP::uri]] {
"/presentations*" {
HTTP::redirect "http://some.site.com/information/download-resources.aspx"
return
}
}
}
}
}
}
}
- Joel_MosesNimbostratusNo need to have two switch statements checking HTTP::host. You could try something like this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "events.oursite.com" { switch -glob [string tolower [HTTP::uri]] { "/eventpage.aspx?event=something08" { HTTP::redirect "http://redirecteddomain.com" } } } "adifferentsite.com" { switch -glob [string tolower [HTTP::uri]] { "/presentations*" { HTTP::redirect "http://some.site.com/information/download-resources.aspx" } } } } }
- Joe_PipitoneNimbostratusWow - you just saved me from frustration. Thank you for your help, it is much appreciated!
- Joe_PipitoneNimbostratusHi Joel,
- Joel_MosesNimbostratusGlad to help!
Recent Discussions
Related Content
* 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