Forum Discussion
jcline
Nimbostratus
Jun 14, 2013Need help making Irule more efficient
Below is a sample of what is running. Each country/culture has two seperate if statements because we don't want to disrupt flow to other items in those folders. We are in the middle of switching f...
Kevin_Stewart
Employee
Jun 14, 2013At a minimum you should probably use an if/elseif structure to avoid unnecessary evaluations. Also, for everything except your single "contains" conditional, you could use a switch context, which is generally faster.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] contains "/home/admin-tools/" } {
HTTP::redirect "http://[HTTP::host]/home/"
} else {
switch [string tolower [HTTP::uri]] {
"/" { HTTP::redirect "http://mysite.com/home/" }
"/gb/eng/default.asp" -
"/gb/eng/" { HTTP::redirect "http://[HTTP::host]/en-gb/" }
"/fr/fra/default.asp" -
"/fr/fra/" { HTTP::redirect "http://[HTTP::host]/fr-fr/" }
}
}
}
Given that you have 20 countries to check for, and presumably 40 conditions, it may also make sense to throw everything into a data group for easier management:
Example data group (my_country_datagroup)
"/" := "/home/"
"/gb/eng/default.asp" := "/en-gb/"
"/gb/eng/" := "/en-gb/"
"/fr/fra/default.asp" := "/fr-fr/"
"/fr/fra/" := "/fr-fr/"
Example iRule:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] contains "/home/admin-tools/" } {
HTTP::redirect "http://[HTTP::host]/home/"
} else {
if { [class match [string tolower [HTTP::uri]] equals my_country_datagroup] } {
HTTP::redirect "http://[HTTP::host][class match -value [string tolower [HTTP::uri]] equals my_country_datagroup]"
}
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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