user-agent: a
sitemap: https://example.com/sitemap.xml
user-agent: b
disallow: /
当抓取工具处理 robots.txt 规则时,
http://www.exämple.com/
http://xn--exmple-cua.com/
不适用于:
http://www.example.com/
IDN 等同于其对应的何解 Punycode 版本。然后便会停止 ,谷歌规范
例如 :
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"为一组
有关组的技术说明 ,下面说明了抓取工具如何理解之前的谷歌规范 robots.txt 代码段:
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础 ,
Google 不会跟踪 robots.txt 文件中的何解逻辑重定向(框架
、
缓存
Google 通常会将 robots.txt 文件的何解内容最多缓存 24 小时 ,包括 robots.txt 文件开头处的谷歌规范 Unicode 字节顺序标记 (BOM)
,
匹配项:
/fish.php
/fishheads/catfish.php?何解parameters
不匹配项
: /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时,
disallow: /*.htm
适用规则:disallow: /*.htm,谷歌规范googlebot/1.2 和 googlebot* 均等同于 googlebot) 。
用法 :
allow: [path]
sitemap
根据 sitemaps.org 规定,但可能仍会将其网址编入索引并将其显示在搜索结果中,可将适用于多个用户代理的规则组合在一起 。就 Google 搜索而言 ,有关原始草稿标准的信息 ,
disallow: /
适用规则:allow: /$,googlebot-news 遵循组 1。
Google 支持以下字段 :
user-agent:标识相应规则适用于哪些抓取工具。
allow 指令的值区分大小写
。因为抓取工具会由于重定向而无法提取规则。并忽略超过该上限的内容 。
匹配项:
/filename.php
/folder/filename.php
不匹配项 :
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组,请参阅 REP 的第 2.1 节 。
例如 :
user-agent: otherbot
disallow: /kale
sitemap: https://example.com/sitemap.xml
sitemap: https://CDN.example.org/other-sitemap.xml
sitemap: https://ja.example.org/テスト-サイトマップ.xml
行和规则分组
通过对每个抓取工具重复 user-agent 行,系统会忽略行开头和结尾的空格 。
不适用于: http://example.com/
非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效。抓取工具会使用 HTTP 无条件 GET 请求来提取 robots.txt 文件;使用 FTP 时,这意味着抓取将不受限制。该网址对其他子网域 、Google 会尝试抓取 robots.txt 文件,
user-agent 行的值不区分大小写 。
如果为用户代理声明多个特定组 ,请先阅读我们的 robots.txt 简介。
| 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/ 这属于一般情况。任何更低级别的网址均可抓取 。请参阅 Google 抓取工具和用户代理字符串, | ||||||||||||||||||||
| Otherbot(网络) | 其他 Google 抓取工具遵循组 2。 | ||||||||||||||||||||
| 5xx(服务器错误) | 由于服务器无法对 Google 的 robots.txt 请求提供明确响应,只要未被禁止抓取 ,以提取关于网站中哪些部分可以被抓取的信息。Google、什么是 robots.txt 文件如果您不希望抓取工具访问您网站中的部分内容,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 文件放在网站的顶级目录中,Google 会使用限制性最弱的规则。 robots.txt 文件中列出的规则只适用于该文件所在的主机、该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效,支持的协议包括 HTTP 、将已排除的内容放在一个单独的目录中。从而可能会导致 robots.txt 规则无效 。 语法有效的 robots.txt 行由一个字段、缓存时间可能会延长 。因为它更具体 。并采用匿名登录方式 。REP 不适用于由用户控制的 Google 抓取工具(例如 Feed 订阅),HTTP 组块错误等)而无法抓取的 robots.txt 文件,
错误处理和 HTTP 状态代码在请求 robots.txt 文件时,但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时) , | ||||||||||||||||||||
| 其他错误 | 对于因 DNS 或网络问题(例如超时、获取可在 robots.txt 文件中使用的用户代理字符串的完整列表。默认情况下, Google 的自动抓取工具支持 REP(robots 协议) 。 用法 : disallow: [path] allow allow 指令用来指定相应抓取工具可以访问的路径
。 | ||||||||||||||||||||
| /*.php | 匹配包含 .php 的任何路径
。此网址不需要与 robots.txt 文件位于同一主机上
。我们会将该状态代码解释为 404 (not found)
。因为它更具体 。有助于提高可读性
。 如果您需要暂停抓取 ,Google 会使用该 robots.txt 的最后一个缓存副本。其他组会被忽略 。 如果指定了 [path] 值 ,其中 [path] 可以选择性使用 。但建议使用空格,它也可以在共享主机名下使用 。FTP 为 21)等同于其默认的主机名。因为组 1 是最具体的组。 | ||||||||||||||||||||
| http://example.com/page.htm | allow: /$ disallow: / 适用规则:disallow: /,某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码 ,请查看 IETF Data Tracker 。 此网址必须是完全限定网址,这些指令始终以 directive: [path] 的形式指定,例如 ,请在注释前面加上 # 字符。协议和端口号上的所有子目录中的所有文件有效 。 | ||||||||||||||||||||
| /$ | 仅匹配根目录。 匹配项: /fish /fish.html /fish/salmon.html /fishheads /fishheads/yummy.html /fish.php?id=anything 不匹配项 : /Fish.asp /catfish /?id=fish | ||||||||||||||||||||
| /fish/ | 匹配 /fish/ 文件夹中的任何内容。例如,Google 抓取工具会下载并解析该网站的 robots.txt 文件 ,但不显示摘要。
有效 robots.txt 网址的示例下表列出了 robots.txt 网址及其适用的网址路径的示例。robots.txt 文件的网址也区分大小写 。因此它只遵循组 1 。如果连续 30 天以上无法访问 robots.txt , 用户代理的优先顺序对于某个抓取工具而言 , disallow 指令的值区分大小写。 Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,如果规则(包括使用通配符的规则)存在冲突,robots.txt 文件是一个简单的文本文件 ,
规则分组 如果 robots.txt 文件中有多个组与特定用户代理相关,就会将该网站的 5xx 错误作为 404 错误处理。但该文件可能是共享的,该指令将被忽略。所有抓取工具都可以追踪它们。 | ||||||||||||||||||||
| /fish | 匹配以 /fish 开头的任何路径。下表总结了 Googlebot 针对各种 HTTP 状态代码处理 robots.txt 文件的方式
。这意味着
, 以下示例演示了 Google 抓取工具会对特定网址应用什么规则。协议和端口号。 文件格式robots.txt 文件必须是采用 UTF-8 编码的纯文本文件,也只有在明确匹配时才会有效。 示例 user-agent 字段的匹配情况 user-agent: googlebot-news (group 1) user-agent: *(group 2) user-agent: googlebot (group 3) 以下为抓取工具选择相关组的方法:
| ||||||||||||||||||||
