PHP redirection

Asked

Viewed 73 times

3

Is there an API and/or function, in PHP, that redirects the pages of my site, depending on the location of the person ? Example : if not BR, redirect to the English page.

  • You’re the one who should do it.

2 answers

2

  • Hello, welcome to [en.so]! Prefer more explanatory answers, not just based on a link, if possible with examples, because that’s what most users look for here in the OS. Just one more thing, looking at the documentation quickly pointed out, the comment says that this API is deprecated and version 2 should be used: Geoip2.

2

Check if you have the module mod_geoip2 (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 find At this link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.