Forum Discussion
Where is and Country
The goal is to add the rule to a VIP that will redirect to country specific folders on the same VIP. once a user hits the country specific folder they will get a cookie to identify the country choice so I do not want the rule to run very time but can't figure out how to get past the initial looping when a user does not have the country cookie.
The second part is the rule does not seem to work when I use country. Using the rule below I get get the redirect if I change $country to $state but no luck with Country
when CLIENT_ACCEPTED {
set country [class match -value [whereis [IP::client_addr]] equals CTS_COUNTRY]
set state [class match -value [whereis [IP::client_addr] abbrev] equals US_STATE]
log local0. "The country is [whereis [IP::client_addr] country] and the state is [whereis [IP::client_addr] abbrev]"
}
when HTTP_REQUEST {
if {[HTTP::cookie exists "SelectedCountryCode"]} {
log local0. "Cookie found [HTTP::cookie SelectedCountryCode]"
event HTTP_REQUEST disable }
elseif {($country ne "")}{
switch $country {
PA {HTTP::redirect http://www.testdomain.com/nsurvey}
US {HTTP::redirect http://www.testdomain.com/nsurvey}
CA {HTTP::redirect http://www.google.com}
AU {HTTP::redirect http://www.ctstestdomain.com/nsurvey}
GB {HTTP::redirect http://www.testdomain.com/nsurvey}
default {pool www.testdomain.com}
}
}
}
The logging does show Country and state but no redirect for country
: The country is US and the state is PA
: The country is GB and the state is 17
If I do away with the HTTP::cookie exists and use this I can get around the looping issue but the developers would like to use cookie
if { [class match [HTTP::uri] contains US_STATE]} {
event HTTP_REQUEST disable }
Any suggestions?
- Michael_YatesNimbostratusI would suggest looking at the Heat Maps Tech Tip that Colin posted.
- boczon_108037NimbostratusThanks I'll take a look at the Heatmaps and I was able to valdate that the country code was being returned.
- Colin_Walker_12Historic F5 AccountHere's the specific line Michael is referencing:
set cloc [whereis [IP::client_addr] country]
- boczon_108037Nimbostratus
- Kevin_Davies_40Nacreous
when HTTP_REQUEST { set debug 1 if {[HTTP::cookie exists "SelectedCountryCode"]} { set country [HTTP::cookie "SelectedCountryCode"] if {$debug} { log local0. "SelectedCountryCode = [HTTP::cookie SelectedCountryCode ]" } } else { set country [whereis [IP::client_addr] country] } if {$debug} { log local0. "Country is $country" } switch $country { PA { set redirect http://www.testdomain.com/nsurvey} US { set redirect http://www.testdomain.com/nsurvey} CA { set redirect http://www.google.com} AU { set redirect http://www.ctstestdomain.com/nsurvey} GB { set redirect http://www.testdomain.com/nsurvey} default { if {$debug} { log local0. "Unmatched country was $country" } set redirect http://www.testdomain.com } } if {$debug} { log local0. "Redirected to $redirect" } HTTP::redirect $redirect
}
- boczon_108037NimbostratusThanks i'll give it a try the last pool command is just sending to a default pool. The name of the pool just happens to be the FQDN of the web site it is supporting.
- Kevin_Davies_40NacreousIf its the default pool attached to the virtual then you don't need the pool command. It will go to that pool unless you redefine it somewhere.
Kevin (Jarvil)
- Aaron_1015NimbostratusBy the way, I know this is an old thread, but I was looking for something related to whereis and came across this. I think the problem was that the first set command is missing the "country":
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