How to redirect all example.org traffic to example.com from ONLY 1 country?
I have two sites, example.com and example.org and I want to redirect all the peop开发者_运维问答le visiting from a Country X visiting example.org to example.com, how to do it using php or .htaccess ?
in short, both sites will work but for a Country X ip's, the visitors browsing .org will redirect to .com without them knowing
Can't be done with .htaccess.... as far as I know.
You'd need to use php to do some geoip location, detect the counrty and then do a simple php header("Location") change with a 301 redirection.
This is a good free database: http://ipinfodb.com/ip_database.php
You'll just need to import it into a database and query it with php.
You need a GEO IP lookup tool, like http://www.hostip.info/use.html
You can use their service in php - your index.php would like something like this:
$r = file_get_contents("http://api.hostip.info/get_html.php?ip=12.215.42.1");
Alternatively, a much faster method is to purchase the ip database list from max mind (it's $50). http://www.maxmind.com/app/country Then you simply query that database (after loading it into mysql) and bump them based on country.
精彩评论