2017-05-08 59 views
0

網站結構我有一個多區域基礎的網站,我根據IP address.Following將用戶重定向是根據自己國家的用戶重定向代碼。但是,此代碼阻止Googlebot訪問美國以外的網頁。什麼應該是理想的結構,以便googlebot可以訪問每個頁面,並且用戶按照他們的IP地址被重定向?提前致謝。的地理靶向網站

if ($country == "IN") 
     { 
    // do nothing 


     } 

    else if ($country == "BD" ") 
     { 
     header('Location:https://www.exmple.com/directory/bangladesh/index.php'); 

     } 

    else if ($country == "PK" ) 
     { 
     header('Location:https://www.exmple.com/directory/pakistan/index.php'); 
    } 
    else if ($country == "LK") 
     { 
     header('Location:https://www.exmple.com/directory/srilanka/index.php'); 
    } 
    else if ($country == "US") 
     { 
     header('Location:https://www.exmple.com/directory/usa/index.php'); 
    } 
    else if ($country == "CA") 
     { 
     header('Location:https://www.exmple.com/directory/canada/index.php'); 
    } 
    else if ($country == "GB") 
     { 
     header('Location:https://www.exmple.com/directory/uk/index.php'); 
    } 
    else if ($country == "NG") 
     { 
     header('Location:https://www.exmple.com/directory/nigeria/index.php'); 
    } 
    else 
     { 
     header('Location:https://www.exmple.com/directory/global/index.php'); 
    } 
+0

也許設置會話變量,當有人第一次訪問,並將其重定向到你認爲他們想看看這個國家,但如果該變量設置當他們回到主頁時,他們避免重定向。因爲它不僅僅適用於Googlebot。如果加拿大的用戶想要查看英國的目錄,該怎麼辦?他們不能? –

+0

請給出你想說的結構。 – rns

+0

沒有結構性變化,只是沒有自動重定向基於IP地址。或者,如果你這樣做,只有改向第一時間,讓遊客穿越之後,你的整個網站,而不是你目前的猜測是什麼數據的訪問者(或由Googlebot)希望看到的策略。 –

回答

0

如果從訪問頁阻止美國的用戶,但允許來自其他國家的遊客,說印度看到它,服務器將阻止似乎是從美國來的蜘蛛。所以,代碼如下修改將工作:

if ($country == "US") 
     { 
    // do nothing 


     } 

    else if ($country == "BD" ") 
     { 
     header('Location:https://www.exmple.com/directory/bangladesh/index.php'); 

     } 

    else if ($country == "PK" ) 
     { 
     header('Location:https://www.exmple.com/directory/pakistan/index.php'); 
    } 
    else if ($country == "LK") 
     { 
     header('Location:https://www.exmple.com/directory/srilanka/index.php'); 
    } 
    else if ($country == "IN") 
     { 
     header('Location:https://www.exmple.com/directory/india/index.php'); 
    } 
    else if ($country == "CA") 
     { 
     header('Location:https://www.exmple.com/directory/canada/index.php'); 
    } 
    else if ($country == "GB") 
     { 
     header('Location:https://www.exmple.com/directory/uk/index.php'); 
    } 
    else if ($country == "NG") 
     { 
     header('Location:https://www.exmple.com/directory/nigeria/index.php'); 
    } 
    else 
     { 
     header('Location:https://www.exmple.com/directory/global/index.php'); 
    } 
0

您可以使用gethostbyaddr,以檢查是否請求來自谷歌爬蟲,然後用這些信息,你可以決定將用戶重定向。

// Method will return "crawl-66-249-66-1.googlebot.com" 
$host = gethostbyaddr('66.249.66.1'); 

// Check if the host contains a google domain. 
$isGoogle = (strpos($host, 'googlebot.com') !== false); 

要弄清谷歌的有關重定向的機器人比預期的用戶頁面不同的頁面政策,我也不太清楚,如果這是在他們皺起了眉頭。

如果你想檢測比谷歌其他更爬蟲,搜索等網絡爬蟲的IP範圍。

來獲取用戶的IP地址,看看這個答案:https://stackoverflow.com/a/15699240/3421225

+0

這就是谷歌。 bing和其他爬蟲怎麼樣?怎麼樣誰希望看到其他國家的目錄用戶,或使用VPN的是表明他們來自除本國來訪羣衆。是的,我非常確定谷歌恨他們的抓取工具是一個完全不同的頁面而不是普通的訪問者...... –

+0

@LucasKrupinski你將不得不自己檢查一下。你知道讓你在那裏的功能。這並不難,只需查看IP範圍即可。我發現這個:http://ipinfodb.com/robots-ip-address-ranges.php –