Forum Discussion
THASIN
Jan 18, 2012Nimbostratus
GEOIP redirection irule
I just created one rule to redirect based on client Geo IP address. I got timeout error message Pls help me to resolve the issue. when HTTP_REQUEST { if ...
hooleylist
Jan 18, 2012Cirrostratus
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
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