Forum Moderators: mack

Message Too Old, No Replies

IP location redirect

redirect, ip, location

         

cmysites

1:10 am on Dec 10, 2007 (gmt 0)

10+ Year Member



I am looking to setup a redirect based on the users ip. I am not sure if I should simply script it into my splash page or if I should put it in the .htaccess file. Ultimately, what I want to do is:
if ip is from United States: www.xyz.com/states/
if ip is from Canada: www.xyz.com/canada/

--
Max.

jtara

4:41 pm on Dec 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even on a country-wide level, this is so inaccurate that it is better simply to have a country selection that the user makes themselves.

At least make sure that users can override your choice.

It's not something that you can simply "script into the splash page" or "put into the htaccess file". You'll need to put the IP address data into some sort of database, and look IPs up in the database. You'll need some script to do that. You'll need to update the database frequently (it changes daily).

The country block for the U.S. comprises 500k of text. Canada is nearly 100k.

U.S. IP block [ipdeny.com]

The problem with using IP addresses for geolocation is that there is no guarantee that the listed addressees are actually in the countries they were issued to.

All it indicated is that the addresses were issued to the IP-granting authority in a given country. Once issued to a commercial enterprise or organization, there is nothing to stop them from using them anywhere in the world.

All it tells you is what country's IP-granting authority is ultimately in control of an address. What it tells you is political - not physical.

As an example, Google uses U.S. IP addresses for it's routers throughout the world.

chrisranjana

8:45 am on Dec 12, 2007 (gmt 0)

10+ Year Member



You could also buy or find a Geo IP database and use it too.

But the best suggestion would be to allow the user to choose the country.

jtara

4:10 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also buy or find a Geo IP database and use it too

Let me elaborate on that, as it may not be so obvious.

The assigned netblocks will tell you what country an IP address was issued to - nothing more. This list is available for free, though.

There are databases you can purchase that purport to geolocate users to a finer degree - for example, to the state or city level. They do this by "mapping" known routers using probes, by knowing how different providers name their routers, etc. (City names often appear in abbreviated form in router DNS names.)

These database probably provide greater accuracy at the country level as well. But you will have to pay for these databases in most cases, and they still are far from perfect.

rocknbil

11:40 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A far less complex method of manging this - as jtara says initially display the country selection.

Set a cookie.

Upon return, you may direct to the country section based on the cookie, but always provide a navigation back to other countries.

Search engines don't read cookies, so both countries will get slurped up without being (possibly) penalized for any redirecting by IP address.