0

我只想从我的国家访问我的网站,我想通过谷歌和 Facebook 访问我的网站。所以我查看了这些页面:

https://developers.facebook.com/docs/sharing/best-practices#crawl https://support.google.com/webmasters/answer/1061943?hl=en 我写了这个 php 代码:

<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if (!preg_match("/facebook/", $agent) && !preg_match("/bingbot/", $agent) && !preg_match("/Googlebot/", $agent) && $agent != 'Facebot')
{
$country = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
if($country != 'AZ')
{
$error = 'Sorry, we can only serve to Azerbaijan!';
include('error.php');
die;
}
}
?>

它适用于脸书。但是当我想用谷歌获得我的页面速度结果时,我得到“对不起,我们只能为阿塞拜疆服务!” 错误

4

1 回答 1

2

这是 Google Page Speed Insight 的用户代理之一

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Chrome/27.0.1453 Safari/537.36

改变这个

!preg_match("/Googlebot/", $agent)

对此

!preg_match("/Google(bot| Page Speed Insights)/", $agent)
于 2014-09-12T20:15:22.920 回答