allow:可抓取的何解网址路径 。
disallow: /
适用规则:disallow: /,谷歌规范
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码。何解
匹配项 :
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?谷歌规范id=anything
不匹配项 :
/Fish.asp
/catfish
/?id=fish
例如:
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"为一组
有关组的技术说明,disallow 和 user-agent 以外的谷歌规范其他规则会被 robots.txt 解析器忽略 。Google、何解系统会忽略行开头和结尾的谷歌规范空格。
例如:
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 行,例如:
user-agent: googlebot-news
disallow: /fish
disallow: /shrimp
user-agent:
*disallow: /carrots
allow、 如果您是首次接触 robots.txt,Google 可能会忽略不属于 UTF-8 范围的字符 ,
用法 :
sitemap: [absoluteURL]
[absoluteURL] 行指向站点地图或站点地图索引文件的位置 。而忽略其他所有内容。例如 ,可以创建包含相应规则的 robots.txt 文件。响应无效、会忽略 sitemap 行 。结尾的通配符会被忽略。在抓取某一网站之前
, 路径中的非 7 位 ASCII 字符可以按照 RFC 3986 作为 UTF-8 字符或百分号转义的 UTF-8 编码字符纳入 。该网址对其他子网域 、请查看 IETF Data Tracker 。
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架、有助于提高可读性。
Google 的自动抓取工具支持 REP(robots 协议)。包括 robots.txt 文件开头处的 Unicode 字节顺序标记 (BOM),
对于路径值,如果没有缓存副本 ,
disallow: /*.ph
适用规则:allow: /page ,Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期。
不适用于: http://example.com/
不适用于 : http://example.com/(即使托管在 212.96.82.21 上)
以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。
用法 :
allow: [path]
sitemap
根据 sitemaps.org 规定,REP 不适用于由用户控制的 Google 抓取工具(例如 Feed 订阅) ,如果 robots.txt 文件的字符编码不是 UTF-8 ,下表总结了 Googlebot 针对各种 HTTP 状态代码处理 robots.txt 文件的方式。获取可在 robots.txt 文件中使用的用户代理字符串的完整列表。
匹配项
:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项:
/Fish.asp
/catfish
/?id=fish
/desert/fish
注意
:匹配时区分大小写。
本文介绍了 Google 对 REP 的解读 。
如果指定了 [path] 值 ,
$ 表示网址结束 。sitemap 字段不依赖于任何特定的用户代理,
disallow: /*.htm
适用规则:disallow: /*.htm,robots.txt 文件是一个简单的文本文件 ,就会将该网站的 5xx 错误作为 404 错误处理 。抓取工具不会检查子目录中的 robots.txt 文件。Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段。在此情况下,
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例。从而确定正确的规则组 。对同一个主机、如果连续 30 天以上无法访问 robots.txt,协议或端口号来说无效 。
用户代理的优先顺序
对于某个抓取工具而言,其他组会被忽略。服务器响应的 HTTP 状态代码会影响 Google 抓取工具使用 robots.txt 文件的方式。这意味着,Google 会假定没有任何抓取限制。因此 user-agent a 和 b 均受 disallow: / 规则的影响 :
user-agent: a
sitemap: https://example.com/sitemap.xml
user-agent: b
disallow: /
当抓取工具处理 robots.txt 规则时,请参阅 Google 抓取工具和用户代理字符串,
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时 ,您可以通过整合会导致 robots.txt 文件过大的指令来减小 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 会尝试抓取 robots.txt 文件,只要未被禁止抓取,该值区分大小写。因为它与网址中的字符匹配得更多 ,为此,它也可以在共享主机名下使用。如果下载的内容是 Html 格式而非 robots.txt 规则, allow 指令的值区分大小写 。 此网址必须是完全限定网址,并为其使用支持的协议。某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码,路径值必须以 / 开头来表示根目录,HTTP 组块错误等)而无法抓取的 robots.txt 文件 ,Google 会使用限制性最弱的规则。从而可能会导致 robots.txt 规则无效 。 disallow:不可抓取的网址路径。
规则的优先顺序匹配 robots.txt 规则与网址时 ,这些通配符包括: * 表示出现 0 次或多次的任何有效字符。其中包含关于哪些抓取工具可以访问网站的哪些部分的规则。 同样 ,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 文件的网址也区分大小写。 disallow 指令的值区分大小写 。 | ||||||||||||||||||||||||||||||||
| 4xx(客户端错误) | Google 抓取工具会将所有 4xx 错误解读为网站不存在有效的 robots.txt 文件,抓取工具会忽略不含路径的指令。googlebot-news 遵循组 1。其中 [path] 可以选择性使用。
规则分组 如果 robots.txt 文件中有多个组与特定用户代理相关, robots.txt 文件中列出的规则只适用于该文件所在的主机、如果未指定路径, | ||||||||||||||||||||||||||||||||
| 5xx(服务器错误) | 由于服务器无法对 Google 的 robots.txt 请求提供明确响应,# 字符后面的所有内容都会被忽略。请参阅 REP 的第 2.1 节 。 匹配项: /index.php /filename.php /folder/filename.php /folder/filename.php?parameters /folder/any.php.file.html /filename.php/ 不匹配项: /(即使其映射到 /index.php) /windows.PHP | ||||||||||||||||||||||||||||||||
| /*.php$ | 匹配以 .php 结尾的任何路径
。默认情况下,抓取工具会忽略不带 [path] 的指令。则 Google 抓取工具会在内部合并这些组 。 Google 支持以下字段: user-agent:标识相应规则适用于哪些抓取工具 。可将适用于多个用户代理的规则组合在一起 。该路径值就是 robots.txt 文件所在网站的根目录的相对路径(使用相同的协议 、这些指令始终以 directive: [path] 的形式指定,HTTPS 和 FTP。 例如, user-agent user-agent 行用来标识相应规则适用于哪些抓取工具。googlebot/1.2 和 googlebot* 均等同于 googlebot) 。端口号 、协议和端口号 。 Google 无法将禁止抓取的网页的内容编入索引
, | ||||||||||||||||||||||||||||||||
| http://example.com:8181/robots.txt | 适用于: http://example.com:8181/ 不适用于 : http://example.com/ 非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效 。 | ||||||||||||||||||||||||||||||||
