如何识别国家和地区相应地更改 URL
我们有三个域名,一个用于美国,一个用于英国,一个用于加拿大。我希望我的用户应该自动重定向到特定于国家/地区的 URL,无论他们打开哪个域。例如,如果用户来自美国并且他正在打开 example.co.uk,那么他/她应该被重定向到 example.com。
we have three domains one for US, one for UK, and one for Canada. i want that my users should be automatically redirected to country specific URL no matter what domain they open.e.g. if the user is from US and he is opening example.co.uk then he/she should be redirected to example.com.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试通过IP来识别国家。例如,请参阅 http://www.ip2location.com/
这不会覆盖所有人,但对于大多数情况来说应该没问题。
You can try to identify the country by IP. For example see http://www.ip2location.com/
This will not cover everybody, but should be ok for most cases.
有两种选择:
1) 使用
MultiViews
选项配置您的 Web 服务器,以查找浏览器设置并显示适当的页面。2) 使用
mod_rewrite / .htaccess
并根据Accept-Language
HTTP 标头重定向用户。有关完整详细信息,请参阅答案 在这里。谢谢。
There are two options:
1) Configure your web server with the
MultiViews
option to look for browser settings and show appropriate page.2) Use
mod_rewrite / .htaccess
and redirect the user based onAccept-Language
HTTP header.For complete details, please see the answer here. Thanks.
康拉德的评论再怎么强调也不为过。除了重定向之外,您还可以向用户提供重定向吗?或者如果您只是重定向,则发送一个横幅,告诉他们已重定向并询问他们是否不想被重定向?如果他们选择不希望被重定向,您可以将他们重定向回来,并通过 URL 中的额外子句或通过 cookie 确保他们不会再次向前重定向。
用一个故事来说明这种烦恼:我的新炉灶坏了。我无法访问 electrolux.com。我被重定向到 electrolux.ch。似乎有一个疑难解答程序,但链接已损坏。 .ch 网站肯定不是他们的主要开发方,德语也不是他们的主要网站语言。该链接可能在英文的 .com 下有效,但伊莱克斯不允许我测试该链接。
或者,如果我在一个国家/地区并且不会说该国家/地区的语言,因此希望保留原始 URL 并使用该语言?
或者,认为我在另一个国家/地区的表弟向我发送了 .com 链接,但我无法打开它?
有很多恼人的场景。
Konrad's comment cannot be high-lighted enough. Instead of just redirecting could you offer the user to be redirected - or if you just redirect send a banner telling they were redirected and asking whether they wanted not be redirected? If they chose, they wanted not to be redirected, you redirect them back and ensure via extra clause in the URL or by cookie that they would not be redirected forward again.
Just one story to illustrate the annoyance: My new hob is broken. I can't access electrolux.com. I am redirected to electrolux.ch. There seems to be a troubleshooter but the link is broken. The .ch site is for sure not their primary development side and German not their primary site language. The link may work under .com in English, but Electrolux does not allow me test that.
Or, if I am in a country and don't speak the country's language and therefore would want to stay at the original URL and use that language?
Or, think my cousin in another country is sending me a .com link and I can't open it?
There are many annoyance scenarios.
我正在为我的一位客户寻找类似的解决方案。幸运的是,我们使用的是Wordpress,并且能够使用这个插件 http://wordpress.org/extend/plugins/ ip2country/ 制作特定于国家/地区的内容条件和模板。这个插件利用了这里找到的 Geolite http://dev.maxmind.com/geoip/geolite 希望这个有帮助。
I was look for a similar solution for one of my clients. Fortunately we were using Wordpress and were able to use this plugin http://wordpress.org/extend/plugins/ip2country/ to make country specific content conditions and templates. This plugin leverages Geolite found here http://dev.maxmind.com/geoip/geolite hope this helps.