如何編寫和優化WordPress網站的Robots.txt

要知道WordPress robots.txt檔案中的“Disallow”命令與頁面頭部的元描述noindex 的作用不完全相同。您的robots.txt會阻止抓取,但不一定不進行索引,網站檔案(如圖片和文件)除外。如果搜尋引擎從其他地方連結,它們仍然可以索引您的“不允許爬取”的頁面。

如何編寫和優化WordPress網站的Robots.txt配圖

因此,Prevent Direct Access Gold不再使用robots.txt禁止規則阻止您的網站頁面進行搜尋索引。相反,我們使用  noindex元標記,這也有助於谷歌和其他搜尋引擎正確地在您的網站上為您的內容分發其入站連結值。

Yoast建議保持robots.txt乾淨  ,不要阻止包括以下任何內容:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-content/plugins/
Disallow: /wp-includes/
User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php Disallow: /wp-content/plugins/ Disallow: /wp-includes/
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-content/plugins/
Disallow: /wp-includes/

WordPress也同意說理想的robots.txt 不應該禁止任何東西。事實上,  /wp-content/plugins/ 和  /wp-includes/ 目錄包含您的主題和外掛可能用於正確顯示您的網站的影象,JavaScript或CSS檔案。阻止這些目錄意味著外掛和WordPress的所有指令碼,樣式和影象被阻止,這使得Google和其他搜尋引擎的抓取工具難以分析和理解您的網站內容。同樣,你也不應該阻止你/wp-content/themes/

簡而言之,禁止你的WordPress資源,上傳和外掛目錄,許多人聲稱可以增強你的網站的安全性,防止任何目標易受攻擊的外掛被利用,但實際上可能弊大於利,特別是在SEO方面。或者,您應該解除安裝這些不安全的外掛更實際些。

這就是我們預設從robots.txt中刪除這些規則的原因。但是,您可能仍希望將它們包含在WordPress的Robots.txt內。

建議包含Sitemap檔案

儘管Yoast強烈建議您直接手動將XML站點地圖提交到Google Search Console和Bing網站管理員工具,但您仍可將sitemap新增到robots.txt,幫助搜尋引擎快速爬取收錄你的網站頁面。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Sitemap: http://yourdomain.com/post-sitemap.xml
Sitemap: http://yourdomain.com/page-sitemap.xml
Sitemap: http://yourdomain.com/author-sitemap.xml
Sitemap: http://yourdomain.com/offers-sitemap.xml
Sitemap: http://yourdomain.com/post-sitemap.xml Sitemap: http://yourdomain.com/page-sitemap.xml Sitemap: http://yourdomain.com/author-sitemap.xml Sitemap: http://yourdomain.com/offers-sitemap.xml
Sitemap: http://yourdomain.com/post-sitemap.xml
Sitemap: http://yourdomain.com/page-sitemap.xml
Sitemap: http://yourdomain.com/author-sitemap.xml
Sitemap: http://yourdomain.com/offers-sitemap.xml

Robots.txt的其他規則

出於安全,建議您阻止您的WordPress的readme.html,licence.txt和wp-config-sample.php檔案訪問,以便未經授權的人員無法檢查並檢視您正在使用的WordPress版本。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
Disallow: /readme.html
Disallow: /licence.txt
Disallow: /wp-config-sample.php
User-agent: * Disallow: /readme.html Disallow: /licence.txt Disallow: /wp-config-sample.php
User-agent: *
Disallow: /readme.html
Disallow: /licence.txt
Disallow: /wp-config-sample.php

您還可以使用robots.txt對不同的搜尋引擎爬蟲定製不同的爬取規則,如下示例。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# block Googlebot from crawling the entire website
User-agent: Googlebot
Disallow: /
# block Bingbot from crawling refer directory
User-agent: Bingbot
Disallow: /refer/
# block Googlebot from crawling the entire website User-agent: Googlebot Disallow: / # block Bingbot from crawling refer directory User-agent: Bingbot Disallow: /refer/
# block Googlebot from crawling the entire website
User-agent: Googlebot
Disallow: /

# block Bingbot from crawling refer directory
User-agent: Bingbot
Disallow: /refer/

這是如何阻止蜘蛛抓取WordPress搜尋結果,強烈建議加入此規則:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
Disallow: /?s=
Disallow: /search/
User-agent: * Disallow: /?s= Disallow: /search/
User-agent: *
Disallow: /?s=
Disallow: /search/

HostCrawl-delay 是您可能考慮使用的其他robots.txt指令,儘管不太受歡迎。第一個指令允許您指定網站的首選域(www或非www):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
#we prefer non-www domain
host: yourdomain.com
User-agent: * #we prefer non-www domain host: yourdomain.com
User-agent: *
#we prefer non-www domain
host: yourdomain.com

下面的規則是用來告訴搜尋引擎蜘蛛在每次抓取之前等待幾秒鐘。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
#please wait for 8 seconds before the next crawl
crawl-delay: 8
User-agent: * #please wait for 8 seconds before the next crawl crawl-delay: 8
User-agent: *
#please wait for 8 seconds before the next crawl 
crawl-delay: 8

完整的robots.txt

綜上所述,我們建議WordPress的robots.txt內容編寫為:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-admin/
Disallow: /wp-login.php
Disallow: /readme.html
Disallow: /licence.txt
Disallow: /wp-config-sample.php
Disallow: /refer/
Disallow: /?s=
Disallow: /search/
#we prefer non-www domain(填入你的網站域名首選域名,一般帶www,請根據實際情況填寫,部分搜尋引擎不支援此規則,慎重新增)
host: yourdomain.com
#please wait for 8 seconds before the next crawl(填入你希望爬蟲爬取頁面的延遲秒數)
crawl-delay: 8
Sitemap: http://yourdomain.com/post-sitemap.xml
User-agent: * Allow: /wp-admin/admin-ajax.php Disallow: /wp-admin/ Disallow: /wp-login.php Disallow: /readme.html Disallow: /licence.txt Disallow: /wp-config-sample.php Disallow: /refer/ Disallow: /?s= Disallow: /search/ #we prefer non-www domain(填入你的網站域名首選域名,一般帶www,請根據實際情況填寫,部分搜尋引擎不支援此規則,慎重新增) host: yourdomain.com #please wait for 8 seconds before the next crawl(填入你希望爬蟲爬取頁面的延遲秒數) crawl-delay: 8 Sitemap: http://yourdomain.com/post-sitemap.xml
User-agent: *
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-admin/
Disallow: /wp-login.php
Disallow: /readme.html 
Disallow: /licence.txt 
Disallow: /wp-config-sample.php
Disallow: /refer/
Disallow: /?s= 
Disallow: /search/

#we prefer non-www domain(填入你的網站域名首選域名,一般帶www,請根據實際情況填寫,部分搜尋引擎不支援此規則,慎重新增)
host: yourdomain.com

#please wait for 8 seconds before the next crawl(填入你希望爬蟲爬取頁面的延遲秒數) 
crawl-delay: 8

Sitemap: http://yourdomain.com/post-sitemap.xml

溫馨提示:上述完整的robots.txt僅供參考,請各位站長根據自己的實際情況編寫內容,其中User-agent: *規則即對所有搜尋引擎蜘蛛通用;Allow: 規則即允許爬取;Disallow: 規則即不允許爬取;host:規則用於指定網站首選域;crawl-delay:規則用於設定爬蟲爬取時間間隔;Sitemap:規則用於設定網站的地圖地址。

評論留言

脣槍舌劍 (7)

  • 云点的頭像

    云点

    2021.6.11 12:06

    一般wp网站保持默认就足够用了
    User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    回覆
  • 华风夏韵的頭像

    华风夏韵

    2021.2.17 16:02

  • python爱好者换友链www.wpon.cn的頭像

    python爱好者换友链www.wpon.cn

    2020.4.10 09:04

    老板,请问这样设置是否正确
    User-agent: *
    Allow: /wp-admin/admin-ajax.php
    Disallow: /wp-admin/
    Disallow: /wp-login.php
    Disallow: /readme.html
    Disallow: /licence.txt
    Disallow: /wp-config-sample.php
    Disallow: /refer/
    Disallow: /?s=
    Disallow: /search/
    #we prefer non-www wpon.cn
    host: http://www.wpon.cn
    #please wait for 8 seconds before the next crawl
    crawl-delay: 8
    Sitemap: https://www.wpon.cn/post-sitemap.xml

    回覆
    • WBOLT_COM

      2020.4.10 17:04

      @python爱好者 最佳方式,去百度搜索资源平台检测一下即可。

  • 非礼勿言yelin的頭像

    非礼勿言yelin

    2020.2.16 15:02

    谢谢开发了这么多不错的插件。安装了插件设置好之后网站根目录没有看到robots.txt文件,另外sitemap.xml也是404,请问需要怎么解决这个。

    回覆
  • 奶爸的笔记的頭像

    奶爸的笔记

    2019.6.5 19:06

    其实某seo插件官方的建议是不禁止索引任何文件。

    回覆
    • WBOLT_COM

      2019.6.5 20:06

      @奶爸的笔记 说是这么说,但一些不需要被搜索引擎索引的,禁止就OK了,不然爬了也是白爬。