PHP Redirect

2

Is there any API and / or function, in PHP, that redirects the pages of my site, according to the locality of the person? Example: If it is not BR, redirect to the English page.

    
asked by anonymous 23.06.2016 / 20:07

2 answers

1

PHP offers a native function for this, take a look at Geo IP Location .

    
23.06.2016 / 20:57
1

Make sure you have the mod_geoip2 module (GeoIP Extension) installed on your server.

Then change your .htaccess as below:

 GeoIPEnable On
 GeoIPDBFile /path/to/GeoIP.dat

 # Start Redirecting countries

# Canada
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://canada.abcd.com$1 [L]

# India
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule ^(.*)$ http://india.abcd.com$1 [L]

# etc etc etc...

The official documentation you will find This link

    
14.10.2016 / 20:59