GEO IP Redirect

Discussion in 'Coding Help' started by Byron, May 25, 2011.

  1. Byron

    Byron New Member

    Hi Guys,

    I did this years ago and now forget how to do it again :( does anyone have any code for automatically and seemlessly redirecting visitors based on their IP.

    Basically what I am trying to do:

    If an Irish IP visitor, site goes to http://www.domain.com

    If a UK IP visitor, site goes to http://www.domain.com/uk/

    ... and I know there are exceptions to this working, but a general one which will catch 99% of users.

    Scripting on site is simple enough PHP / HTML on Linux server with Cpanel (yes I am learning the other hosts options too :p)

    Thanks In Advance,
    B
     
  2. php.allstar

    php.allstar New Member

    Hi Byron,

    Try this, its an apache module you'll need control of apache configuration though so it won't work on shared hosts.

    Also not sure about the seo implications...is this deemed as cloaking?
     
  3. Byron

    Byron New Member

    Thanks for that,

    Hmm anything for a shared host? - I remember vaguely using javascript although I may be wrong. I don't know if it would be cloaking, as the content would be different on the redirected page, and also the url wouldn't be rewritten at all. - Just a redirect based on IP.

    Thanks,
    B
     
  4. mneylon

    mneylon Administrator Staff Member

    You can use maxmind or one of the other services / solutions - I think there was a thread discussing it a while back
    Javascript isn't a good solution
     
  5. Byron

    Byron New Member

    Hi blacknight,

    Gonna take a look around, but thanks for the tips, yea found some nasty hack I used years ago, but a database backed system seems best
     
  6. mneylon

    mneylon Administrator Staff Member

    From what I remember we implemented something along these lines ..

    php include that grabbed the user's ip.. do a lookup against a data source of IPs (geoip obviously) .. based on the result send the user to a particular page

    On one site we were doing it simply to stop people from outside a subset of countries accessing an order form ..
     
  7. Byron

    Byron New Member

    Sounds like a plan!

    I found this option which seems suitable: ip2nation - resolve IP to country

    I don't have any huge need for specific areas so it should cover the UK as a whole.

    I'll let you know if it turns out to be a failure!
     
  8. mneylon

    mneylon Administrator Staff Member

    As long as the data is relatively fresh you should be ok ..

    Now here's an interesting problem for you .. how do you get that to work with IPv6? :)
     
  9. Byron

    Byron New Member

    A month old, so I would say it will be fine... god I'm gonna cry, how long is the lifetime of IPv4 now :p and how would I make it compatible for IPv6... you really should have a website with lots of Google Adsense for all this!
     
  10. mneylon

    mneylon Administrator Staff Member

    Now you've given me an idea :) (though I have a sneaky suspicion I already grabbed a domain for it a while back .. )
     
  11. Byron

    Byron New Member

    God when will I actually get work done and get off this forum to blog about work, then maybe get some work done
     
  12. mneylon

    mneylon Administrator Staff Member

    Well that's a good thing to say about the site if you actually want to spend time here :)
     

Share This Page