How to do a conditional redirect based on source location
July 28, 2009 6:18 AM   Subscribe

How can I do a redirect based on a users location, but only for the landing page of a website and not subfolders or files?

We have a site: http://www.example.com. A country specific version of this site has been developed: http://aus.example.com/. This offers features specific to these users from Australia.

All traffic originating from Australia needs to be redirected to aus.example.com when visiting the landing page of http://www.example.com.

However, there are some special services provided by http://www.example.com:
http://www.example.com/freecarwash
http://www.example.com/submityourtaxes

These services are not provided by aus.example.com so all traffic to these pages need to be routed to www.example.com as usual.

In other words, how can I redirect only Australian traffic destined for the home page of http://www.example.com to aus.example.com but leave other traffic untouched.

Some relevant points:
1. The server for the subdomain aus.example.com is located in a different country to www.example.com.
2. A webserver / dns solution would be preferable to a page based solution.
posted by Gomez_in_the_South to Computers & Internet (5 answers total)
 
This is a two part problem.

1) Identifying country of origin (this is hard). You really have no way of knowing where someone is coming from, even if you ignore issues like proxies. You might get 90%* certainty, and that's about it.

2) Redirecting from just that homepage to your target page (this is easy). The answer for this part depends entirely on your operating system and webserver software. A solution for IIS 7 will look different than one for IIS 6 which will look different from Apache ...

* number plucked from thin air
posted by adipocere at 6:24 AM on July 28, 2009


Response by poster: Thanks adipocere - I'm aware of the limitations of identifying the country of origin. We can assume for this argument that this isn't an issue.

I'm still trying to get detailed information about the server configuration at http://www.example.com, I believe it is running Apache.
posted by Gomez_in_the_South at 7:03 AM on July 28, 2009


You won't get 90% certainty on country, but you might get 90% on "not Australia", which seems to be your concern.

If you must do this, please please please make it easy for users to go back to the country they actually wanted in the first place before the 'helpful' redirect.

(Because what about Americans traveling in Australia, or users in the Philippines who have an Australian proxy?)

The polite thing to do is to make sure the other website is always one-click away. "Click here for Australian site", and "Click here for International site" on all pages. Or a splash "Choose Your Website" page that sets a cookie (once), so that you can use the cookie for ensuing visits. That way you are trusting/empowering the user to choose the site they wanted.

And always make it reversible. That way your redirect is just sending them a default that they might have chosen anyway. But let them change it back, please.
posted by rokusan at 12:35 PM on July 28, 2009


Try googling "geotargeting script".

For that matter, here's a package that includes one (it seems to work rather well, though I didn't use it for long):

http://www.hypnoticphp.com/

And here's a pricier script that includes a redirection function:

http://www.ip2country.net/geo-targeting/geo-targeting.html
posted by darth_tedious at 8:29 PM on July 28, 2009


Response by poster: Thanks, everyone, for the advice.

rokusan, as a user of the internet I agree with your views. In this case, these decisions aren't mine to make. I was trying to get some other ideas before I went ahead with a specific solution.

In the end we're using a script based solution. I have proposed a more suitable, higher level solution, but that will take longer to implement as it involves other teams and red tape.
posted by Gomez_in_the_South at 2:26 AM on August 28, 2009


« Older Off the rack   |   Ordering a return ticket Melbourne to Los Angeles... Newer »
This thread is closed to new comments.