robots.txt 實用規則
以下是 robots.txt 一些常見的實用規則:
| 實用規則 | |
|---|---|
| 禁止檢索整個網站 |
提醒您,在某些情況下,未經檢索的網站網址仍可能會編入索引。 User-agent: * Disallow: / |
允許檢索整個網站 (使用空白的 Disallow 規則) |
這會明確允許所有檢索器存取整個網站。這與完全沒有 robots.txt 檔案,或是使用 User-agent: * Disallow: |
| 禁止檢索特定目錄及其中內容 |
在目錄名稱後方附加正斜線,即可禁止檢索整個目錄。 User-agent: * Disallow: /calendar/ Disallow: /junk/ Disallow: /books/fiction/contemporary/ |
|
禁止檢索單一網頁 |
例如,禁止檢索位於 User-agent: * Disallow: /useless_file.html Disallow: /junk/other_useless_file.html |
|
禁止檢索整個網站,但子目錄除外 |
檢索器只能存取 User-agent: * Disallow: / Allow: /public/ |
| 允許單一檢索器存取網站內容 |
只有 User-agent: Googlebot-News Allow: / User-agent: * Disallow: / |
| 允許所有檢索器存取網站內容,但某一個檢索器除外 |
User-agent: Unnecessarybot Disallow: / User-agent: * Allow: / |
|
禁止檢索整個網站,但允許 |
這麼做會讓您的網頁無法顯示在 Google 搜尋結果中,但 User-agent: * Disallow: / User-agent: Storebot-Google Allow: / |
|
禁止 Google 檢索您網站上的所有圖片 (包括 Google 圖片和探索專區等 Google 顯示圖片的任何位置) |
Google 不得為未經檢索的圖片和影片建立索引。 User-agent: Googlebot-Image Disallow: / |
|
禁止 Google 圖片檢索特定圖片 |
例如,禁止 User-agent: Googlebot-Image Disallow: /images/dogs.jpg |
|
禁止檢索特定類型的檔案 |
例如,禁止檢索所有的 User-agent: Googlebot Disallow: /*.gif$ |
使用 * 和 $ 萬用字元來比對結尾為特定字串的網址 |
例如,封鎖所有 User-agent: Googlebot Disallow: /*.xls$ |
| 將多個使用者代理程式合併為單一群組 |
將多個檢索器的規則整合到一個群組,可縮短檔案長度並簡化管理作業,因為群組中的所有規則都會套用至列出的每個使用者代理程式。這樣做等同於列出使用者代理程式兩次,並分別套用規則。 User-agent: Googlebot User-agent: Storebot-Google Allow: /cats Disallow: / |