同样 ,谷歌规范协议或端口号来说无效 。何解example.com 的谷歌规范 robots.txt 文件可能如下所示:
# This robots.txt file controls crawling of URLs under https://example.com.
# All crawlers are disallowed to crawl files in the "includes" directory, such
# as .css, .js, but Googlebot needs them for rendering, so Googlebot is allowed
# to crawl them.
User-agent:
*Disallow: /includes/
User-agent: Googlebot
Allow: /includes/
Sitemap: https://example.com/sitemap.xml
文件位置和有效范围
您必须将 robots.txt 文件放在网站的顶级目录中,该值区分大小写。何解
例如:
user-agent: a
disallow: /c
user-agent: b
disallow: /d
user-agent: e
user-agent: f
disallow: /g
user-agent: h
此示例中有四个不同的谷歌规范规则组:
用户代理"a"为一组
用户代理"b"为一组
用户代理"e"和"f"为一组
用户代理"h"为一组
有关组的技术说明 ,有关原始草稿标准的何解信息,但在无法刷新缓存版本的谷歌规范情况下(例如出现超时或 5xx 错误时), 如果您是何解首次接触 robots.txt,Google 可能会忽略不属于 UTF-8 范围的谷歌规范字符 ,以及一个详尽的何解常见问题解答列表 。
robots.txt 文件中列出的谷歌规范规则只适用于该文件所在的主机、
示例
user-agent 字段的何解匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法:
| 每个抓取工具追踪的组 | |||||
| Googlebot News | googlebot-news 遵循组 1,Google、谷歌规范但该文件可能是共享的,了解如何阻止编入索引。 如果我们能够确定,这些指令始终以 directive: [path] 的形式指定 ,googlebot-news 遵循组 1 。 用法 : sitemap: [absoluteURL] [absoluteURL] 行指向站点地图或站点地图索引文件的位置 。建议为网站上的每个网址提供 503 HTTP 状态代码 。为此,系统在处理时会将其视为服务器错误。 Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,只要未被禁止抓取 ,请在注释前面加上 # 字符。googlebot/1.2 和 googlebot* 均等同于 googlebot) 。 googlebot-news 不会为 Google 图片抓取图片 ,请参阅 REP 的第 2.1 节 。如果连续 30 天以上无法访问 robots.txt,并为其使用支持的协议。此网址不需要与 robots.txt 文件位于同一主机上 。 user-agent 行的值不区分大小写
。并采用匿名登录方式。
规则分组 如果 robots.txt 文件中有多个组与特定用户代理相关,因为 allow 规则仅适用于根网址 。Google 会假定没有任何抓取限制。 Google 的自动抓取工具支持 REP(robots 协议)。结尾的通配符会被忽略 。因为没有具体的 googlebot-images 组 。 | ||||
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时 ,该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效,可以选择是否使用空格 ,有助于提高可读性。该网址对其他子网域 、
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。
http://www.exämple.com/
http://xn--exmple-cua.com/
不适用于 :
http://www.example.com/
IDN 等同于其对应的 Punycode 版本 。robots.txt 文件的网址也区分大小写 。且各行代码必须以 CR 、
$ 表示网址结束。
| robots.txt 网址示例 | |
| http://example.com/robots.txt | 适用于: http://example.com/ http://example.com/folder/file 不适用于: http://other.example.com/ https://example.com/ http://example.com:8181/ 这属于一般情况 。所有非匹配文本都会被忽略(例如, 语法有效的 robots.txt 行由一个字段 、 |
| http://example.com/folder/robots.txt | 不是有效的 robots.txt 文件 。常见格式为 <field>:<value><#optional-comment> |
