Can someone help me - what is the best way to redirect all non U.S. traffic to another domain. I have been searching google and cannot decide which is the best way to go so I am looking for suggestions?.
I think you would be able to achieve this using Apache rewrite rules but I'm pretty sure it would be sub-optimal. The way I would do it would be to use MaxMind's GeoIP database with PHP and MySQL. MaxMind have two products for GeoIP... one is free, the other is £12 per month. The free one puts ISPs like AOL in America regardless of where the IP is actually located. The paid one is really quite good and even managed to locate our datacentre down to about 5 miles. The free one is accurate for about 90% of all IPs, the paid one is accurate for about 99% There is a reference implementation in PHP on their website and I found a tutorial on how to import the .csv version of the database into MySQL. You could always use the .dat file as they do in their example but my preference is to have a database stored in a dedicated database server. Make sure to have a way for users to get back to the US domain and stay there, because no Geo -> IP lookup is going to be 100% accurate and you might send one the wrong way.
Thanks for the info, I have been looking at a couple of other databases and will check out your suggestion also.
Maxmind also provides an apache module for its GeoIP database. Just load the module and use htaccess redirects using set geoip environment vars.
yes, maxmind is in my opinion the best route. You can use their free country database. 1) download max mind, compile. 2) add entires into apache httpd.conf file to use the new module 3) decide which countries you wish to block and you can add them into a .htaccess file like this (this is what I block): GeoIPEnable On GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry SetEnvIf GEOIP_COUNTRY_CODE ID BlockCountry SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry # ... place more countries here Deny from env=BlockCountry
This is very useful Sebastian - thank you for posting it. One thing, how would you adjust the code, so that instead of denying people from those countries, it redirected them to another website please ? Any help appreciated. Kezi.
Just in-case anyone else finds this thread looking for the same answer here you go GeoIPEnable On GeoIPDBFile /path/to/GeoIP.dat # Redirects ALL countries except UK/GB RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^GB RewriteRule ^(.*)$ http://www.your_redirect_url.com$1 [L]
Many thanks Peter - it's much appreciated. I thought there had to be someone that knew the answer ;-)