我有一个网站 www.xyz.com,其中包含特定国家/地区 X 的内容。此外,我在同一域的子域(例如 subdomain.xyz.com)上还有另一个目标到不同国家/地区 Y 的网站
我可以使用任何免费的 geo ip 数据库和一些 php 脚本来实现重定向,我成功地做到了这一点,但现在的问题是
来自 Y 国的访问网站 www.xyz.com 的人被重定向到 subdomain.xyz.com,但假设他想要检查 www.xyz.com,它会再次将他们重定向到 subdoamin.xyz.com。
我希望这是谷歌的方式,这样,如果假设从阿联酋访问 google.com 的人被重定向到 google.ae,但如果他们点击“转到 Google.com”,他们就会被重定向到 google.com,没有任何问题。
我需要为我的网站实现这个..
该网站采用 WordPress。请建议我最好的解决方案。
好的,这是我使用过的代码..
/**
* Example 6
*
* This is what google probably do with users around the world
*
* Multiple declatations
*/
// Start by including CountryDetector class
include("./src/CountryDetector.class.php");
// You dont need to create instance of this class you can access only on static context
// Google.co.uk
CountryDetector::redirect("AE", "http://uae.jobscow.com");
// Google Germania
CountryDetector::redirect(array("DE", "AT"), "http://google.de"); // Ausrian and German users
// Google China
CountryDetector::redirect("CN", "http://google.cn");
// Google sweden
CountryDetector::redirect("SE", "http://google.se");
// Google norwegia
CountryDetector::redirect("NO", "http://google.se");
// Google serbia
CountryDetector::redirect("RS", "http://google.rs");
// AND SO ON...
// Finally: Google.com - international
CountryDetector::redirect("international", "http://google.com");
?>
您建议我对此进行哪些更改
最佳答案
使用引荐来源网址检查:如果他们到达 www.xyz.com 并且引荐来源网址不是国家/地区网站,则重定向到国家/地区网站。
如果他们在国家/地区网站上点击“转到 www.xyz.com”,引荐来源网址将为country.xyz.com,然后您就不会重定向。
您还可以使用 cookie 来存储客户在这方面的偏好。
RFC2616 section 14.36解释了 Referer header 字段,以及 this article展示如何在 php 中使用它。
编辑:作为替代方案 - 因为正如 lars 所说,用户或路径上的某些内容可能会停用它/删除标题 - 您可以在 www.xyz 上使用虚拟“登陆页面”,暗示访问者来自的服务器国家服务器:
<a href="www.xyz.com/fromcountryserver.php">Go to xyz</a>
或者为什么不添加一个请求变量来指示浏览器来自国家/地区服务器。愚蠢的例子只是为了表明意图
<a href="www.xyz.com/index.php?comingfrom=countryserver">Go to xyz</a>
或这些技术的混合。需要做更多的工作,但除非某些疯子在客户端重写 URL,否则它应该始终有效。
关于php - 将用户重定向到特定国家/地区的子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7292840/