Geo Location Redirection

While I can't help how to exactly achieve this, I looked into exactly this for my site a couple of weeks back and was advised on another forum (where I was looking to hire someone to do this for me) that it was a really bad idea to re-direct based on location/IP; if you're doing this for language purposes, the argument is that people living in certain places may not speak the native language.

Just my 2 cents =)
 
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

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
 
Last edited:
If you are doing this purely for the language selection, then the above answers are good and there are plenty of PHP examples using the maxmind "free" database available.

If you are using this to divert to servers nearer the location of the customer, this would be most efficiently done using a CDN service.
 
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

Thank you for the help
 
It seems simple to do, then you need to update the website to have us price etc.

But how do you do it with WHMCS you just create different packages with dollars?
 
The provided code and CDN will help you in this case. Also if you are using the CMS for developing the website then there are plugins which will help you to achieve the requires result.
 
Geo targeting

I dont know why you would want to force a redirect , like somebody said above the person may well not speak the language you are assuming he is.

Anyway i have done this for a website before, and from a seo perspective google does not like the redirect as it is termed a re direct and not good for user experience.

What google does advise is sub directories with copies of you web page in the language and then using the appropriate href lang tags.

Landing on a English site and seeing the word ( Francias or whatever ) as a link on there for those whom would prefer it is a much better way of implementing this.

If your href tags have been implemented properly and you are showing them on google webmaster tools and have the sub directory then google will be well aware that you offer the site in both languages and now forcing a german guy whom probably uses english online to a german version of the your site.
 
If you doing because of language issue then you not need to do this. Just used language relational code in your header section google can find it.
 
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.
 
Back
Top