How to Redirect based on IP (country)
-
Hi!
What I need to know is if I can redirect a visitor based on his country.
I mean, I know I can do that with a php file, calling the GeoIp database, but to do it I have to put it on my domain root and mysite.com becames a redirection script to mysite.com/uk and mysite.com/us, etc.
Here′s the php example script:
<?php require_once("geoip/geoip.inc"); $gi = geoip_open("geoip/GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code == 'fr') { header("HTTP/1.1 301 Moved Permanently"); header('Location: https://mysite.com/fr/'); } else { header("HTTP/1.1 301 Moved Permanently"); header('Location: https://mysite.com/en/'); } ?>
What I want is to know if it′s possible to redirect using .htaccess or any other method, or just with the php method I refered above.
Because what I want is something like this:
– visitors click on a link to mysite.com and if it is US citizen nothing happens and he enter on mysite.com, if it′s French or Brazilian, enter on mysite.com/international/
Besides that, if possible, I also want this:
– visitor click on a link to mysite.com/hosting/ and if it is a US citizen nothing happens and he enter on mysite.com/hosting/, if it′s French or Brazilian, enter on mysite.com/hosting/international/
Conclusion:
– for every page on my site, I want to have a “mirror” version (with a no index tag), just with different banners and different small portions of text for where I want to redirect all my international traffic.
If anyone could help me I would be very appreciated.
- The topic ‘How to Redirect based on IP (country)’ is closed to new replies.