I want to access my site from ONLY my country and I want to google and facebook can access to my site. So I looked to the these pages:
https://developers.facebook.com/docs/sharing/best-practices#crawl https://support.google.com/webmasters/answer/1061943?hl=en And I writed this php code:
<?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;
}
}
?>
It works on facebook. But when I want to get my page speed results with google, i get "Sorry, we can only serve to Azerbaijan!" error
This is the one of the user agent of 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
Change this
!preg_match("/Googlebot/", $agent)
to this
!preg_match("/Google(bot| Page Speed Insights)/", $agent)