简体   繁体   English

根据国家/地区-HTACCESS重定向用户?

[英]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.

相关问题 从ip检测国家并重定向到相应的国家 - Detect country from ip and redirect to according country 显示根据用户所在国家/地区的jquery价目表 - Showing a jquery price list according to users' country 如何根据国家IP地址重定向域 - how to redirect domain according to country IP address 如何根据国家/地区明智地重定向到文件 - How to redirect to file according to country wise Maxminds GeoIP php 根据国家代码重定向 - Maxminds GeoIP php Redirect according to country code 根据用户所在国家/地区的网址将用户重定向到正确的数据库,我使用kohana框架使用i18n for php和im - Redirect users to the correct database according to their country on the url, i worked with i18n for php and im using kohana framework 根据国家/地区和运营商重定向移动用户 - Redirect mobile users based on country and carrier .htaccess根据PHP参数和一般情况重定向 - .htaccess redirect according to PHP parameters and general case 如何根据两个用户在PHP中的角色重定向 - How to redirect two users according to their roles in PHP 使用.htaccess和国家/地区位置(在网站网址中)重定向到自定义404页面 - Redirect to custom 404 page using .htaccess and country location (in website url)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM