views:

552

answers:

5

We basically have 2 sites ( Java /JSP / Apache Webserver) : something.ca & something.com

The .ca is canadian content, and the .com is american content.

We need users to be redirected based on the ip addreess. We want US users to get the .com site and Canadian users get the .ca site.

What is the best way to do this (at a webserver level or otherwise ) ?

Please elaborate.

+3  A: 

In my web surfing experience, most websites - UPS.com for example - ask the user to select their country site rather than trying to figure it out themselves. They remember the selection in a cookie. Much depends on how voluntary your use case requires this redirection to be.

On the implementation side, I'd use a filter that would check the setting and fire a redirect if need be.

sblundy
+2  A: 

Check out GeoDirection. It may handle what you want through javascript.

http://www.geobytes.com/GeoDirection.htm

Another option would be to grab the culture from the browser environment settings and map those cultures to countries in your application. Depending on what you are actually trying to do this may not work for you as this will not give you the user's physical location, but will get you their preferred culture. So if a Canadian travels to the US they will still get the Canadian site unless they changed their browser settings for some reason.

David Osborn
+1  A: 

There are a lot of IP geolocation APIs out there - I don't know if there's anything good out there that you don't have to pay for:

Herb Caudill
+1  A: 

Using culture settings is an option, but doesn't work in some cases. What if you have a German user in the US who likes his dates etc. displayed in the format he's comfortable with? Doesn't change the fact that he's in the US.

I think that's one of the reasons why most companies simply ask the user and then store that information in a cookie (UPS, FedEx and most major airlines do that). Check out www.lufthansa.com. They actually ask for location and language(to account for countries with more than one official language like Switzerland).

Stefan
+3  A: 

I've used GeoIP from Maxmind and it works well. They have a free version GeoCountry Lite That's 99.3% accurate. the Java API is here I would follow google's practice of having a link back to the original version if you do the redirect.

Bryan Waters