Gaby-HostDept
New member
Can any one explain me how to redirect a website according to visitor location like www.example.com should redirect to us.example.com for united states visitor
Can any one explain me how to redirect a website according to visitor location like www.example.com should redirect to us.example.com for united states visitor
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(US)$
RewriteRule ^(.*)$ http://www.us.example.com$1 [R,L]
$ip = $_SERVER['REMOTE_ADDR'];
$co = geoip_country_code_by_name($ip);
if($co == "US")
{
header("Location: http://us.example.com");
}
else {
// do whatever you want
}
You can use mod_geoip, or geoip extension for php, with GeoIP.dat database from Maxmind and simple with .httaccess:
Code:RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(US)$ RewriteRule ^(.*)$ http://www.us.example.com$1 [R,L]
or with php (with geoip extension):
Code:$ip = $_SERVER['REMOTE_ADDR']; $co = geoip_country_code_by_name($ip); if($co == "US") { header("Location: http://us.example.com"); } else { // do whatever you want }
Regards
+1 I also use these tools.Hi there, I have used simlar PHP Api's to this and i have a free one you can use, dm me so we can discuss further. It is a custom script I use.