[英]Redirect users according to country -HTACCESS?
. 。 Consider my domain name is www.example.com .
考虑我的域名是www.example.com。 It is in english
用英语
And i have have one language version for dutch www.example.com/nl 我有荷兰语的一种语言版本www.example.com/nl
I want to redirect url to www.example.com/nl only for people requesting from Netherland. 我只想将网址重定向到www.example.com/nl,以供来自荷兰的请求者使用。
My website is in shared hosting. 我的网站在共享主机中。 How can i achieve this ?
我怎样才能做到这一点?
You can redirect based on the browser's language setting coming from the user: 您可以根据来自用户的浏览器语言设置进行重定向:
RewriteCond %{HTTP:Accept-language} nl [NC]
RewriteRule ^$ /nl [L,R=301]
You have to use GeoIP service and determine country of your visitor and then do the proper redirect. 您必须使用GeoIP服务并确定访客的国家/地区,然后进行正确的重定向。
Download Geo API for PHP here http://geolite.maxmind.com/download/geoip/api/php/ 在此处下载适用于PHP的Geo API, 网址为http://geolite.maxmind.com/download/geoip/api/php/
There are samples how to use the code. 有示例如何使用代码。
It would be something like 就像
include("geoipcity.inc");
include("geoipregionvars.php");
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$_SERVER['REMOTE_ADDR']);
if ( $record->country_code == "NL" ) {
header('Location: http://www.yoursite.com/nl');
}
Take a look at the apache module mod_geoIP, might do what you want, but otherwise you're going to have to rely on a script to get the geolocation information and redirect based on that. 看一下apache模块mod_geoIP,它可能会做您想要的事情,但是否则,您将不得不依靠脚本来获取地理位置信息并基于该信息进行重定向。
As a side topic, IP lookup isn't 100% accurate in regards to getting geolocation information, so be careful. 附带说一句,就获取地理位置信息而言,IP查找不是100%准确的,因此请当心。 Often it is a better idea to let the user choose first time round, and then save a cookie to remember this choice.
通常最好让用户第一次选择,然后保存一个cookie来记住此选择。
Edit: And yes @Pekka has a good point, there is tons of information about it on Google. 编辑:是的,@ Pekka有一个优点,在Google上有很多关于它的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.