Pass Country Code in URL using iRule and Geolocation

Here is a simple example that explains how to pass Country Code as variable in URL using iRule. I assume that you have already configured your F5 appliance with GeoLocation database, otherwise refer my article BIG-IP LTM url redirection based on Geolocation and set it up.

In this example, when someone browse www.itadminguide.com, HTTP::path returns “/” and passes $client_country variable value in the URL – https://[HTTP::host]/member/Login.do?location=$client_country, passes $client_country

when HTTP_REQUEST {
set client_country [whereis $client_ip country]
if {[active_members appserver_pool]<1}
{ HTTP::redirect “https://itadminguide.com/under-maintenance” }
elseif { [HTTP::path] eq “/” }
{ HTTP::redirect “https://[HTTP::host]/member/Login.do?location=$client_country” }
else
{ pool appserver_pool}
}