BIG-IP LTM url redirection based on Geolocation

There is no necessity to rewrite about downloading and installing Geo-location database as we have a friendly article written in F5 repository here. You can follow as guided in the article and you should be able to successfully complete setting up Geo-location in your F5 box.

 

[admin@nlb01:Active:In Sync] ~ # cd /shared/tmp

[admin@nlb01:Active:In Sync] tmp # md5sum -c ip-geolocation-1.0.1-20160303.221.0.zip.md5
ip-geolocation-1.0.1-20160303.221.0.zip: OK

[admin@nlb01:Active:In Sync] tmp # unzip ip-geolocation-1.0.1-20160303.221.0.zip

Archive:  ip-geolocation-1.0.1-20160303.221.0.zip
inflating: geoip-data-Region2-1.0.1-20160303.221.0.i686.rpm
inflating: geoip-data-ISP-1.0.1-20160303.221.0.i686.rpm
inflating: geoip-data-Org-1.0.1-20160303.221.0.i686.rpm
inflating: geoip-data-v6-1.0.1-20160303.221.0.i686.rpm
inflating: README.txt

[admin@nlb01:Active:In Sync] tmp # geoip_update_data -f geoip-data-Region2-1.0.1-20160303.221.0.i686.rpm
[admin@nlb01:Active:In Sync] tmp # geoip_update_data -f geoip-data-ISP-1.0.1-20160303.221.0.i686.rpm
[admin@nlb01:Active:In Sync] tmp # geoip_update_data -f geoip-data-Org-1.0.1-20160303.221.0.i686.rpm
[admin@nlb01:Active:In Sync] tmp # geoip_update_data -f geoip-data-v6-1.0.1-20160303.221.0.i686.rpm

Now in iRule, redirect your visitors of main website to different geographical edition of website based on their IP address. Geo-location database has IP address to Country Code mapping, which is actually an ISO 2 digit country code (refer www.countrycode.org for any specific country code).

when HTTP_REQUEST {
if {[HTTP::path] eq “/” }
{
set client_ip [IP::client_addr]
set client_country [whereis $client_ip country]
if { $client_ip ne “” } {
switch [string toupper [whereis $client_ip country]] {
“OM” { HTTP::redirect “http://www.itadminguide.om” }
“KW” { HTTP::redirect “http://www.itadminguide.kw” }
“AE” { HTTP::redirect “http://www.itadminguide.ae” }
“QA” { HTTP::redirect “http://www.itadminguide.qa” }
default { HTTP::redirect “https://itadminguide.com” }
}
}
}
}

Its very important that you use absolute URI in HTTP::redirect

All in One WordPress Hosting Starts at 30$ per month
All in One WordPress Hosting
WordPress
High optimized WordPress hosting, secure firewall, HTTPS, Backup, hack-fix guarantee and many others at 30$ per month

Helpful Geolocation CLI commands:

# geoip_lookup 8.8.8.8To query the IP geolocation database for the location of a specific IP address
# geoip_lookup -f /shared/GeoIP/F5GeoIPOrg.dat 8.8.8.8To query a specific IP geolocation database file using -f command
# ls -ltr /shared/GeoIP/To findout the release date of the IP geolocation database file that is stored in your F5 appliance