Magento 2 中的 Robots.txt 是什么?
robots.txt 文件指示网络爬虫了解在何处为您的网站建立索引以及在何处跳过。定义网站机器人与网站爬虫的关系将帮助您优化网站的排名。有时您需要它来识别并避免对特定部分建立索引,这可以通过配置来完成。您可以决定使用默认设置还是为每个搜索引擎设置自定义说明。
配置 Magento 2 robots.txt 文件的步骤
请按照此分步指南在 Magento 2 中配置 robots.txt 文件:
- 在管理面板上,单击
Stores
。在“Settings
”部分中,选择Configuration
。 - 在左侧面板中选择
Design
下General
- 打开该
Search Engine Robots
部分,然后继续执行以下操作:- 在 中
Default Robots
,选择以下选项之一:- 索引、关注
- NOINDEX,关注
- 索引、不关注
- NOINDEX、NOFOLLOW
- 如果需要,请在
Edit Custom instruction of robots.txt File
字段中输入自定义说明。 - 如果您需要恢复默认说明,请在该
Reset to Defaults
字段中单击按钮。Reset to Default
- 在 中
- 完成后,单击
Save Config
。
Magento 2 Robots.txt 示例
您还可以通过设置自定义说明来隐藏您的页面,使其不被网站抓取工具发现,如下所示:
- 允许完全访问
User-agent:*
Disallow:
- 禁止访问所有文件夹
User-agent:*
Disallow: /
Magento 2 默认 Robots.txt
Disallow: /lib/
Disallow: /*.php$
Disallow: /pkginfo/
Disallow: /report/
Disallow: /var/
Disallow: /catalog/
Disallow: /customer/
Disallow: /sendfriend/
Disallow: /review/
Disallow: /*SID=
Disallow: /*?
# Disable checkout & customer account
Disallow: /checkout/
Disallow: /onestepcheckout/
Disallow: /customer/
Disallow: /customer/account/
Disallow: /customer/account/login/
# Disable Search pages
Disallow: /catalogsearch/
Disallow: /catalog/product_compare/
Disallow: /catalog/category/view/
Disallow: /catalog/product/view/
# Disable common folders
Disallow: /app/
Disallow: /bin/
Disallow: /dev/
Disallow: /lib/
Disallow: /phpserver/
Disallow: /pub/
# Disable Tag & Review (Avoid duplicate content)
Disallow: /tag/
Disallow: /review/
# Common files
Disallow: /composer.json
Disallow: /composer.lock
Disallow: /CONTRIBUTING.md
Disallow: /CONTRIBUTOR_LICENSE_AGREEMENT.html
Disallow: /COPYING.txt
Disallow: /Gruntfile.js
Disallow: /LICENSE.txt
Disallow: /LICENSE_AFL.txt
Disallow: /nginx.conf.sample
Disallow: /package.json
Disallow: /php.ini.sample
Disallow: /RELEASE_NOTES.txt
# Disable sorting (Avoid duplicate content)
Disallow: /*?*product_list_mode=
Disallow: /*?*product_list_order=
Disallow: /*?*product_list_limit=
Disallow: /*?*product_list_dir=
# Disable version control folders and others
Disallow: /*.git
Disallow: /*.CVS
Disallow: /*.Zip$
Disallow: /*.Svn$
Disallow: /*.Idea$
Disallow: /*.Sql$
Disallow: /*.Tgz$
更多 Robots.txt 示例
阻止 Google 机器人访问文件夹
User-agent: Googlebot
Disallow: /subfolder/
阻止 Google 机器人访问某个页面
User-agent: Googlebot
Disallow: /subfolder/page-url.html
常见的网络爬虫(Bot)
以下是互联网上一些常见的机器人。
User-agent: Googlebot
User-agent: Googlebot-Image/1.0
User-agent: Googlebot-Video/1.0
User-agent: Bingbot
User-agent: Slurp # Yahoo
User-agent: DuckDuckBot
User-agent: Baiduspider
User-agent: YandexBot
User-agent: facebot # Facebook
User-agent: ia_archiver # Alexa