Forum Discussion
nrelihan_68143
Jul 08, 2011Nimbostratus
Redirecting to regional website depending on user DNS.
Hey all, I'm quite new to F5 irules first of all.
Perhaps I'll tell you what I have working first and then explain to you what additional things I'd like to do.
What I have working
When somebody goes to www.fakewebsite.com it looks at their dns location and redirects it to their a regional website, in my example here, its Ireland and UK. So when somebody goes to this website when in Ireland it will redirect them to www.fakewebsite.com/ireland and to www.fakewebsite.co.uk when in the UK.
I have two pools setup, one for ireland and one for the UK.
Global traffic irule
when DNS_REQUEST {
if {[whereis [IP::client_addr]] contains "IE"} {
pool pool-Ireland
} elseif {[whereis [IP::client_addr]] contains "GB"} {
pool pool-UK
} else {
pool pool-default
pool-UK Local traffic irule
when HTTP_REQUEST {
if {[HTTP::uri] equals "/" } {
HTTP::respond 302 Location "http://www.fakewebsite.com/ireland/"
}
}
pool-Ireland Local traffic irule
when HTTP_REQUEST {
if {[HTTP::uri] equals "/"} {
HTTP::respond 302 Location "http://www.fakewebsite.co.uk/"
}
}
What Im looking to do
Im looking to enhance this like so:
For example when somebody is located in the UK types www.fakewebsite.com/pictures the irule would redirect them to the UK website but including the static page they requested, www.fakewebsite.co.uk/pictures.
When somebody is located in irealnd they type www.fakewebsite.com/pictures the irule would redirect them to www.fakewebsite.com/ireland/pictures.
What I'm afriad though is that if somebody based in Ireland but for some reason had a UK ip address and visa versa, typed in www.fakewebsite.com/ireland, it would still re-direct them to the .co.uk website. So in other words they would never be able to get to the .com/ireland website.
So would it be possible to include a rule that would not allow this to occur.
Maybe the rule might say, if they type in www.fakewebsite.com/ireland, do not put it though an irule?
Any help is appreciated, my brain is melting trying to get working code for this!
Thanks alot!
Neil
- Peter_72728NimbostratusI don't think the logic to add URI rewriting that retains the requested URI (i.e. www.fakewebsite.CO.UK/pictures) would be too hard. In fact you might get away with something like this in your pool-UK Local traffic irule:
- nrelihan_68143NimbostratusHey Peter, thanks for your response. Your correct, in your response to my last question. I did'nt think it through correctly.
IRELAND POOL when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "http://www.fakewebsite.com" \ and [string tolower [HTTP::uri]] starts_with "/ireland"} { HTTP::respond 302 Location http://www.fakewebsite.com/[HTTP::uri] } else { HTTP::respond 302 Location http://www.fakewebsite.com/ireland/[HTTP::uri] } } UK POOL when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "http://www.fakewebsite.com" \ and [string tolower [HTTP::uri]] starts_with "/ireland"} { HTTP::respond 302 Location http://www.fakewebsite.com/[HTTP::uri] } else { HTTP::respond 302 Location http://www.fakewebsite.co.uk/[HTTP::uri] } }
- Peter_72728NimbostratusOne issue I see at first glance...These expressions will not work because HTTP::host does not contain the protocol...
- Peter_72728NimbostratusThis looks like it would allow a redirect loop. Why do you need to do anything in this case? The domain is already correct and the "/ireland" context already exists.
- nrelihan_68143NimbostratusSorry Peter I dont follow, what do you mean they dont contain the protocol?
- nrelihan_68143Nimbostratusyes your code is a lot more efficient than what I had,
- Peter_72728NimbostratusCorrect!
- The_BhattmanNimbostratusHi Neil,
- Colin_Walker_12Historic F5 AccountJust out of curiosity, is there a reason you're using HTTP::respond 302 Location rather than just using HTTP::redirect?
- Colin_Walker_12Historic F5 AccountWorth noting: I ask because the HTTP::redirect command issues a 302 by default.
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