Forum Discussion
dean_02_164511
Nimbostratus
Aug 18, 2015Geolocation with more than one country
I created the below little snippet to check the country code and redirect. What is the easiest way to format the below if I wanted to see if it was from multiple countries like US, JP, CN, etc.
...
VernonWells
Employee
Aug 18, 2015Using a switch:
when HTTP_REQUEST {
switch -glob [whereis [IP::client_addr]] {
"*US*" -
"*CA*" -
"*UK*" {
HTTP::redirect "http://www.example1.com/"
}
"*MX*" -
"*CR*" {
HTTP::redirect "http://www.example2.com/"
}
default {
HTTP::redirect "http://www.example3.com/"
}
}
}
or a datagroup:
ltm data-group internal country-redirect {
records {
CA {
data http://www.example1.com/
}
CR {
data http://www.example2.com/
}
MX {
data http://www.example2.com/
}
UK {
data http://www.example1.com/
}
US {
data http://www.example1.com/
}
}
type string
}
along with:
when HTTP_REQUEST {
set redir [class match -value -- [whereis [IP::client_addr]] contains country-redirect]
if { $redir ne "" } {
HTTP::redirect $redir
}
else {
HTTP::redirect "http://default.example.com/"
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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