简体   繁体   中英

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 people 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM