2014-09-12 56 views
0

我想从我的国家访问我的网站,我想谷歌和脸书可以访问我的网站。所以,我看了对这些页面:php让谷歌和脸书访问我的网站

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上。但是,当我想用​​谷歌获得我的页面速度结果时,我得到“对不起,我们只能服务于阿塞拜疆!”错误

回答

1

这是谷歌网页速度洞察

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) 
+0

如果我改变了大家谁使用谷歌的一个铬可以访问我的网站 – 2014-09-12 20:17:03

+0

@AliyevRauf只需编辑它以匹配机器人和页面速度 – Isaac 2014-09-12 20:21:29