透過給網站設定適當的 robots.txt 對 Google 和百度 seo 最佳化的作用是很明顯的。 WordPress 部落格網站也一樣。
我們先看看 robots.txt 是什麼,有什麼作用?
robots.txt 是什麼?
我們都知道 txt 字尾的檔案是純文字檔案,robots 是機器人的意思,所以顧名思義,robots.txt 檔案也就是給搜尋引擎蜘蛛這個機器人看 的純文字檔案。 robots.txt 是搜尋引擎公認遵循的一個規範文 檔,它告訴 Google 、百度等搜尋引擎哪些網頁允許抓取、索引並在搜尋結果中顯示,哪些網頁是被禁止收錄的。 搜尋引擎蜘蛛 spider(Googlebot/Baiduspider) 來訪問你的網站頁面的時候,首先會檢視你的網站根目錄下是否有 robots.txt 檔案,如 果有則按照裡面設定的規則許可權對你網站頁面進行抓取和索引。如淘寶網就透過設定 robots.txt 遮蔽百度搜尋引擎:
| User-agent: Baiduspider Disallow: / User-agent: baiduspider Disallow: / |
robots.txt 的作用
我們瞭解了什麼是 robots.txt,那它有什麼作用,總體來說,robots.txt 檔案至少有下面兩方面的作用:
1 、透過設定遮蔽搜尋引擎訪問不必要被收錄的網站頁面,可以大大減少因 spider 抓取頁面所佔用的網站頻寬,小網站不明顯,大型網站就很明顯了。
2 、設定 robots.txt 可以指定 google 或百度不去索引哪些網址,比如我們透過 url 重寫將動態網址靜態化為永久固定連結之後,就可以透過 robots.txt 設定許可權,阻止 Google 或百度等搜尋引擎索引那些動態網址,從而大大減少了網站重複頁面,對 SEO 最佳化起到了很明顯的作用。
robots.txt 的寫法
關於如何寫 robots.txt 檔案,在下面我們會以 WordPress 部落格來作更具體舉例說明。這裡先提示幾點 robots.txt 寫法中應該注意的地方。如 robots.txt 檔案裡寫入以下程式碼:
| User-agent: * Disallow: Allow: / |
robots.txt 必須上傳到你的網站根名錄下,在子目錄下無效;
robots.txt,Disallow 等必須注意大小寫,不能變化;
User-agent,Disallow 等後面的冒號必須是英文狀態下的,冒號後面可以空一格,也可以不空格。網上有人說冒號後面必須有空格,其實沒有也是可以的,請看谷歌中文網站管理員部落格的設定就是這樣:http://www.googlechinawebmaster.com/robots.txt ;
User-agent 表示搜尋引擎 spider:星號 「*」 代表所有 spider,Google 的 spider 是 「Googlebot」,百度是 「Baiduspider」;
Disallow: 表示不允許搜尋引擎訪問和索引的目錄;
Allow: 指明允許 spider 訪問和索引的目錄,Allow: / 表示允許所有,和 Disallow: 等效。
robots.txt 檔案寫法舉例說明
|
禁止 Google/百度等所有搜尋引擎訪問整個網站 |
User-agent: * |
|
允許所有的搜尋引擎 spider 訪問整個網站 (Disallow: 可以用 Allow: /替代) |
User-agent: * |
|
禁止 Baiduspider 訪問您的網站,Google 等其他搜尋引擎不阻止 |
User-agent: Baiduspider |
|
只允許 Google spider: Googlebot 訪問您的網站,禁止百度等其他搜尋引擎 |
User-agent: Googlebot |
|
禁止搜尋引擎蜘蛛 spider 訪問指定目錄 |
User-agent: * |
|
禁止搜尋引擎 spider 訪問指定目錄,但允許訪問該指定目錄的某個子目錄 |
User-agent: * |
|
使用萬用字元星號"*"設定禁止訪問的 url |
User-agent: * |
|
使用美元符號"$"設定禁止訪問某一字尾的檔案 |
User-agent: * |
|
阻止 google 、百度等所有搜尋引擎訪問網站中所有帶有? 的動態網址頁面 |
User-agent: * |
|
阻止 Google spider:Googlebot 訪問網站上某種格式的圖片 |
User-agent: Googlebot |
|
只允許 Google spider:Googlebot 抓取網頁和.gif 格式圖片 |
User-agent: Googlebot |
|
只禁止 Google spider:Googlebot 抓取.jpg 格式圖片 |
User-agent: Googlebot |
Google 和百度對 robots.txt 檔案的介紹: Google robotstxt,百度 robots.txt 。