robots.txt 完整語法

如要瞭解 robots.txt 完整語法,請按這裡。robots.txt 語法有一些較為複雜的須知事項,因此請詳閱整份文件。

實用 robots.txt 規則
以下是一些常見的實用 robots.txt 規則:

規則 範例
禁止檢索整個網站。 提醒您,在某些情況下,即使網站上的網址並未經過檢索,也會被編入索引。注意:使用這項規則時,比對範圍不含各種 AdsBot 檢索器;如要比對 AdsBot 檢索器,必須特別指明。
User-agent: *
Disallow: /
禁止檢索特定目錄及其中所有內容 (請在目錄名稱後加上正斜線)。提醒您,您不應使用 robots.txt 避免私人內容遭到存取:請改用適當的驗證機制。robots.txt 檔案所禁止的網址仍有可能在未經檢索的情況下被編入索引,且因為任何人皆可檢視 robots.txt 檔案,私人內容的位置也可能因此而曝光。
User-agent: *
Disallow: /calendar/
Disallow: /junk/
允許單一檢索器存取網站內容
User-agent: Googlebot-news
Allow: /

User-agent: *
Disallow: /
允許所有檢索器存取網站內容,但某一個檢索器除外
User-agent: Unnecessarybot
Disallow: /

User-agent: *
Allow: /

禁止檢索某個網頁 (請在正斜線後面列出該網頁):

User-agent: *
Disallow: /private_file.html
禁止 Google 圖片檢索特定圖片:

User-agent: Googlebot-Image
Disallow: /images/dogs.jpg
禁止 Google 圖片檢索您網站上的所有圖片:

User-agent: Googlebot-Image
Disallow: /
禁止檢索特定類型的檔案 (例如 .gif):

User-agent: Googlebot
Disallow: /*.gif$
禁止檢索整個網站,但仍在網站所含網頁上顯示 AdSense 廣告。請禁止 Mediapartners-Google 以外的所有網路檢索器。這樣就會將這些網頁排除在搜尋結果之外,但 Mediapartners-Google 網路檢索器仍然可以分析網頁,以決定要對網站訪客顯示的廣告。

User-agent: *
Disallow: /

User-agent: Mediapartners-Google
Allow: /
比對以特定字串結尾的網址。請使用 $,例如使用範例程式碼,即可封鎖任何以 .xls 結尾的網址:
User-agent: Googlebot
Disallow: /*.xls$
分類