rdessert_76127
Dec 06, 2012Nimbostratus
Using switch vs if to clean up irule
I'm attempting to clean up an irule that currently uses lots of "if" statements and want to use the "switch" statement instead. I've attempted to format the iRule as follows, but I cannot seem to get the syntax correct.
Any assistance is much appreciated!
when HTTP_REQUEST {
Redirect to www.site.org
switch -glob [string tolower [HTTP::host]] {
"site.org" -
"site.com" -
"www.site.com"
{
HTTP::respond 301 Location "http://www.site.org[HTTP::uri]"
}
Match uri patterns and redirect to https
switch -glob [string tolower [HTTP::uri]] {
"/uri1*" -
"/uri2*" -
"/uri3*" -
"/uri4*" -
"/uri5*"
{
log local0.alert "https redirect:[HTTP::host]-[HTTP::uri]-[HTTP::path]"
HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
return
}
Match uri's and send traffic to pool
log local0.alert "BEGIN Host:[HTTP::host]-[HTTP::uri]-[HTTP::path]"
switch -glob [string tolower [HTTP::uri]] {
"/" -
"/*" -
"/\\?*" -
"/uri10/*" -
"/uri11/*" -
"/uri12/*" -
"/uri13/*" -
"/uri14/*" -
"/uri15*"
{
log local0.alert "pool1 Host:[HTTP::host]-[HTTP::uri]"
pool pool1
return
}
default {
pool pool2
}
}
}
}