首页 > 解决方案 > Redirect user by geo ip but not googlebot

问题描述

we have two website one for EU users and the other only for users in USA.

I use a simple system that checks the origin of the 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));

After which, based on the response, I redirect the user to the correct site.

if ($countrycode == 'us'){
    // go to usa website 
}else{
   // do nothing 
}

Now, the problem is that Google came from USA, and I need to not redirect the googlebot (and other bot) in the way that it can scan the EU site which is the main one.

I looking a lot on internet and finally I did this:

if( strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot") )  {
        $countrycode = 'en'; // force him to have en instead of us
    }

Now, I'm not very happy about this, Googlebot scan my website but I'm not sure if work really well. Because google speed test see only the USA website. I'm afraid that isn't the best way to deal with this problem.

Do you have any better ideas?

标签: phpredirectgeolocationseogooglebot

解决方案


从谷歌查看本指南

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。


推荐阅读