【问题标题】:Redirect user by geo ip but not googlebot通过地理 ip 重定向用户,而不是 googlebot
【发布时间】: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


    【解决方案1】:

    从谷歌查看本指南

    https://support.google.com/webmasters/answer/182192?hl=en

    我的建议是实现 href-lang 并为每个语言版本设置单独的 URL

    https://support.google.com/webmasters/answer/189077

    我只是将主页通过 302 重定向到相应的语言版本

    所以

    example.com > 302 > example.com/us 如果您在美国 example.com > 302 > example.com/uk 如果你在英国

    并且它们都与引用另一个版本的 href-lang 连接。谷歌将列出

    example.com/us 在美国

    example.com/uk 在英国

    喜欢这个作为主页。对所有子页面执行相同的操作,因此 Google 只会列出英国的 /uk/ 页面。使用这种方法,您不必关心 Googlebot。从理论上讲,它可以向 Googlebot 展示一些不同的东西,但这是有风险的,因为他们不只使用一个 Googlebot。

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 2012-05-31
      • 2020-11-04
      • 2016-11-20
      • 2018-01-05
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多