WordPress搜索引擎seo網(wǎng)站優(yōu)化爬行記錄代碼
寫(xiě)博客也有一段時(shí)間了,(北京網(wǎng)站建設(shè))為什么搜索引擎遲遲不收錄你的頁(yè)面呢?想知道每天都有哪些蜘蛛“拜訪”你的網(wǎng)站嗎?作為一名wordpress用戶(hù)(北京網(wǎng)站制作),有必要知道每天都有哪些蜘蛛爬行過(guò)你的網(wǎng)站,以便于了解各搜索引擎蜘蛛爬行頻率,對(duì)網(wǎng)站進(jìn)行針對(duì)性的SEO網(wǎng)站優(yōu)化。
其實(shí)很簡(jiǎn)單,只要添加以下代碼,然后再調(diào)用文件代碼就OK了,是不是很方便呢?那就開(kāi)始行動(dòng)吧。
之前我也找過(guò)幾個(gè)蜘蛛爬行記錄工具PHP版,結(jié)果都不盡人意。而且這些PHP程序大多要進(jìn)行安裝,還要將蜘蛛爬行記錄添加到MYSQL中,未免太麻煩。那就尋找一個(gè)簡(jiǎn)易的蜘蛛爬行記錄器吧~
googlebot
1.首先,在wordpress主題根目錄建立一個(gè)robots.php文件,寫(xiě)入以下內(nèi)容:
<?php
function get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, ’googlebot’) !== false){
return ’Googlebot’;
}
if (strpos($useragent, ’msnbot’) !== false){
return ’MSNbot’;
}
if (strpos($useragent, ’slurp’) !== false){
return ’Yahoobot’;
}
if (strpos($useragent, ’baiduspider’) !== false){
return ’Baiduspider’;
}
if (strpos($useragent, ’sohu-search’) !== false){
return ’Sohubot’;
}
if (strpos($useragent, ’lycos’) !== false){
return ’Lycos’;
}
if (strpos($useragent, ’robozilla’) !== false){
return ’Robozilla’;
}
return false;
}
function nowtime(){
$date=gmdate(”Y-n-j H:i:s”,time()+8*3600);
return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url=$_SERVER['HTTP_REFERER'];
$file=”robotslogs.txt”;
$time=nowtime();
$data=fopen($file,”a”);
fwrite($data,”Time:$time robot:$searchbot URL:$tlc_thispage\n”);
fclose($data);
}
?>
將其上傳于你的主題目錄內(nèi)。
2.在Footer.php或header.php的適當(dāng)位置添加以下代碼調(diào)用robots.php。
<?php include(’robots.php’) ?>
程序原理:通過(guò)對(duì)蜘蛛標(biāo)識(shí)符(如Baiduspider、Googlebot)的判斷,記錄蜘蛛爬行時(shí)間,并生成日志文件robotslogs.txt于根目錄。
程序缺點(diǎn):無(wú)法記錄蜘蛛爬行的頁(yè)面,功能較為簡(jiǎn)單。