【发布时间】:2019-10-16 19:49:52
【问题描述】:
我们有两个网站,一个供欧盟用户使用,另一个仅供美国用户使用。
我使用一个简单的系统来检查 IP 的来源。
$geo = json_decode(file_get_contents("http://extreme-ip-lookup.com/json/$user_ip"));
$country = $geo->countryCode;
$countrycode = $sanitizer->pageName(substr($country, 0, 2));
之后,根据响应,我将用户重定向到正确的站点。
if ($countrycode == 'us'){
// go to usa website
}else{
// do nothing
}
现在,问题是 Google 来自美国,我不需要重定向 googlebot(和其他机器人),因为它可以扫描主要的欧盟网站。
我在网上看了很多,最后我做到了:
if( strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot") ) {
$countrycode = 'en'; // force him to have en instead of us
}
现在,我对此不太满意,Googlebot 会扫描我的网站,但我不确定是否能正常工作。因为谷歌速度测试只看到美国网站。 恐怕这不是解决这个问题的最佳方法。
你有更好的主意吗?
【问题讨论】:
标签: php redirect geolocation seo googlebot