Forum Discussion
gbunting
Nimbostratus
Mar 19, 2009How to clean up multiple if/else redirects?
I have a current iRule that works. It will redirect from www.domainname.com.au to www.domainname.com/au for multiple international domains. The problem is I currently have 7 if/else statements for 7 international domains and I have just found out that I will need to add approximately 20 more domains. My question is, is there a better way to create this rule that will be more easily manageable given the number of if/els statements I will need to add? I tried looking into using data groups, but I am not sure how to go about parsing them.
Here is my current iRule:
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www.osisoft.com"} {
pool www.osisoft.com
}
elseif { [HTTP::host] starts_with "www.osisoft.com.br"} {
HTTP::redirect "http://www.osisoft.com/Brazil"
}
elseif { [HTTP::host] starts_with "www.osisoft.com.au"} {
HTTP::redirect "http://www.osisoft.com/Australia"
}
elseif { [HTTP::host] starts_with "www.osisoft.com.mx"} {
HTTP::redirect "http://www.osisoft.com/Mexico"
}
elseif { [HTTP::host] starts_with "www.osisoft.com.ca"} {
HTTP::redirect "http://www.osisoft.com/Canada"
}
elseif { [HTTP::host] starts_with "www.osisoft.cz"} {
HTTP::redirect "http://www.osisoft.com/Chech"
}
elseif { ([HTTP::host] starts_with "www.osisoft.co.jp") ||
([HTTP::host] starts_with "www.osisoft.jp") } {
HTTP::redirect "http://www.osisoft.com/Japan"
}
else { pool www.osisoft.com
}
}
Thanks
Glen
- hoolio
Cirrostratus
Hi Glen, - Arie
Altostratus
Have you considered using "switch" instead of if-then? - gbunting
Nimbostratus
I have changed the Irule to use the switch statement as changed the redirect to the 301 respond. Is there any other optimizations I should do? The majority of the traffic will be going to the default pool (www.domainname.com) can this be optimized by adding that to the beginning of the switch statement or is that not necessary?
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