Tuesday 3 July 2012

Redirecting sub domains according to Country

To redirecting any sub domain according to country, install mod_geoip module (GeoIp Extentsion) inside server if it not installed. Write below code in .htaccess file:
GeoIPEnable On
GeoIPDBFile /GeoIp path/GeoIP.dat
#Redirection according to country
# For USA
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^USA$
RewriteRule ^(.*)$ http://us.mysite.com$1 [L]
# For India
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule ^(.*)$ http://in.mysite.com$1 [L]
# For Canada
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://ca.mysite.com$1 [L]

1 comment:

  1. i was looking for cakephp web development and landed up on your post and i think i must appreciate your work.keep rocking.

    ReplyDelete