Forum Discussion
iRule Redirect based on Geolocation issues
I'm trying to create an iRule which redirects based on IP and Geolocation code for the 4 country codes listed. I currently have the following:
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]] {
"AU" { HTTP::redirect "testsite.example.com.au" }
"SG" { HTTP::redirect "testsite.example.com.sg" }
"PH" { HTTP::redirect "testsite.example.com.ph" }
"MY" { HTTP::redirect "testsite.example.com.my" }
default { HTTP::redirect "testsite.example.com" }
}
}
}
}
I sourced this from here: http://itadminguide.com/big-ip-ltm-url-redirection-based-on-geolocation/
However, I'm getting "too many redirect errors" so I suspect it's getting stuck in a loop?
I'm new to this so any help will be much appreciated.
Thanks, Rich
- Anthony_Graber
Employee
Rich, where are you applying this iRule? What's the hostname of the website this is being applied to? Do all of the above hostnames resolve to the IP address that the above iRule is applied to?
Anthony
- Stanislas_Piro2
Cumulonimbus
Hi,
Looking at your irule, you redirect in any condition. Remove the default statement.
Http redirect to different hostname must contain absolute uri
HTTP::redirect "https://testsite.example.com.my"
- Richard24_33536
Nimbostratus
Thanks for the response Anthony, I have the rule applied to a virtual server for the testsite.example.com pool. The hostname would be testsite.example.com, which is the default site I want to direct the client to should the rule fail to match any of those country codes based on IP. All of the country code hostnames listed are CNAMEs back to testsite.example.com. The idea being it simply returns a different URL based on whether it hits any of those country codes.
Recent Discussions
Related Content
* 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