Hi insitha,
There were a few issues with that iRule:
The square braces act like backticks in Linux, executing the string within as a command. You had a few two many sets of braces around your commands.
The URI will always start with "". So that check of the URI would never be false.
You can combine most of the switch cases into one action where you're redirecting to the country specific URL.
Lastly you can use the default keyword in the switch case as a catch-all.
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.example.com" && [HTTP::path] eq "/" }{
Parse the client IP from the CDN header
set client_ip [HTTP::header value "Client-IP"]
if { $client_ip eq "" }{
The header was empty/did not exist, so use the actual client IP
set client_ip [IP::client_addr]
}
set country [string tolower [whereis $client_ip abbrev]]
switch $country {
"af" -
"bh" -
"bd" -
"be" -
"eg" -
"fr" -
"de" -
"in" -
"ir" -
"iq" -
"it" -
"jo" -
"kz" -
"ke" -
"kw" -
"lb" -
"mo" -
"np" -
"nl" -
"om" -
"pk" -
"qa" -
"ru" -
"sa" -
"es" -
"lk" -
"sd" -
"sz" -
"sy" -
"tn" -
"tr" -
"ua" -
"ae" -
"ye" {
HTTP::redirect "http://www.example.com/home-${country}"
}
default {
Redirect all others
HTTP::redirect "http://www.example.com/home"
}
}
} else {
pool example_web_pool
}
}
Aaron