我想从我的国家访问我的网站,我想谷歌和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;
}
}
?>
它适用于Facebook。但是当我想通过谷歌获得我的页面速度结果时,我得到“抱歉,我们只能服务于阿塞拜疆!”错误
答案 0 :(得分: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)