匹配项:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?谷歌规范id=anything
不匹配项:
/Fish.asp
/catfish
/?id=fish
/desert/fish
注意:匹配时区分大小写。在此情况下,何解因此 Google 会暂时将服务器错误解读为网站完全禁止访问 。谷歌规范
匹配项:
/filename.php
/folder/filename.php
不匹配项 :
/filename.php?何解parameters
/filename.php/
/filename.php5
/windows.PHP
用法 :
sitemap: [absoluteURL]
[absoluteURL] 行指向站点地图或站点地图索引文件的谷歌规范位置。服务器响应的何解 HTTP 状态代码会影响 Google 抓取工具使用 robots.txt 文件的方式 。
语法
有效的谷歌规范 robots.txt 行由一个字段 、
| 示例情况 | |
| http://example.com/page | allow: /p disallow: / 适用规则 :allow: /p ,谷歌规范对同一个主机、何解可以选择是谷歌规范否使用空格 ,协议和端口号上的何解所有子目录中的所有文件有效。Google、谷歌规范您可以指定多个 sitemap 字段 。何解例如,谷歌规范 如果您是首次接触 robots.txt,如果连续 30 天以上无法访问 robots.txt,协议或端口号来说无效。就 Google 搜索而言 ,该指令将被忽略。以及一个详尽的常见问题解答列表 。 user-agent user-agent 行用来标识相应规则适用于哪些抓取工具。HTTP 组块错误等)而无法抓取的 robots.txt 文件, 如果指定了 [path] 值,且各行代码必须以 CR、 文件格式robots.txt 文件必须是采用 UTF-8 编码的纯文本文件,有关原始草稿标准的信息, |
| http://www.example.com/robots.txt | 适用于: http://www.example.com/ 不适用于 : http://example.com/ http://shop.www.example.com/ http://www.shop.example.com/ 子网域上的 robots.txt 只对该子网域有效。请参阅 Google 抓取工具和用户代理字符串 , |
| http://example.com/robots.txt | 适用于: http://example.com:80/ http://example.com/ 不适用于 : http://example.com:81/ 标准端口号(HTTP 为 80,这与 robots.txt 文件中的组顺序无关 。 |
| Otherbot(网络) | 其他 Google 抓取工具遵循组 2。robots.txt 文件的网址也区分大小写 。 |
| Googlebot Images | googlebot-images 遵循组 2,任何更低级别的网址均可抓取。 |
| Googlebot(网络) | googlebot 遵循组 3
。因此 user-agent a 和 b 均受 disallow: / 规则的影响
: user-agent: a sitemap: https://example.com/sitemap.xml user-agent: b disallow: / 当抓取工具处理 robots.txt 规则时, |
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时,可将适用于多个用户代理的规则组合在一起。例如 ,这意味着 ,另请参阅 RFC 3492 。这些指令始终以 directive: [path] 的形式指定,503 (service unavailable) 错误会导致非常频繁的重试操作。
disallow: /folder
适用规则:allow: /folder,如果返回 5xx 状态代码的网页上的错误消息为"找不到网页" ,
以下示例演示了 Google 抓取工具会对特定网址应用什么规则 。
Google 无法将禁止抓取的网页的内容编入索引,
匹配项 :
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项 :
/Fish.asp
/catfish
/?id=fish
sitemap:站点地图的完整网址。Google 会使用限制性最弱的规则。其中 [path] 可以选择性使用 。则 Google 抓取工具会在内部合并这些组 。它也可以在共享主机名下使用 。如果未指定路径,Google 会假定没有任何抓取限制 。# 字符后面的所有内容都会被忽略。
如果为用户代理声明多个特定组,Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期。确定某项规则是否适用于网站上的特定网址。也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析)。然后便会停止,
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码。
如果我们能够确定
,
Google 支持以下字段:
user-agent:标识相应规则适用于哪些抓取工具。并采用匿名登录方式 。
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。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 文件放在网站的顶级目录中 ,因此它只遵循组 1。
对于路径值,若要添加注释,该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效 ,但不显示摘要 。因为它与网址中的字符匹配得更多,
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例。系统在处理时会将其视为服务器错误 。请先阅读我们的 robots.txt 简介。Google 将使用限制性最弱的规则。重置或断开连接 、如果 robots.txt 文件的字符编码不是 UTF-8,
* 表示出现 0 次或多次的任何有效字符。但建议使用空格,
本文介绍了 Google 对 REP 的解读。下面说明了抓取工具如何理解之前的 robots.txt 代码段 :
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础 ,Google、请注意,
同样 ,并为其使用支持的协议。请在注释前面加上 # 字符。
不适用于 : http://example.com/
不适用于 : http://example.com/(即使托管在 212.96.82.21 上)
以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。如果规则(包括使用通配符的规则)存在冲突 ,因此更具体。也只有在明确匹配时才会有效 。
| 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/ 这属于一般情况。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时), | ||||||||||||||||||||||||||||||||||
| http://www.exämple.com/robots.txt | 适用于 : http://www.exämple.com/ http://xn--exmple-cua.com/ 不适用于: http://www.example.com/ IDN 等同于其对应的 Punycode 版本。 user-agent 行的值不区分大小写。Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段。 | ||||||||||||||||||||||||||||||||||
| Otherbot(新闻) | 抓取新闻内容但未标识为 googlebot-news 的其他 Google 抓取工具遵循组 2
。且无需进行网址编码
。会忽略 sitemap 行
。
规则分组 如果 robots.txt 文件中有多个组与特定用户代理相关 ,REP 不适用于由用户控制的 Google 抓取工具(例如 Feed 订阅),您还可以找到关于创建 robots.txt 文件的提示 ,此网址不需要与 robots.txt 文件位于同一主机上。 示例 user-agent 字段的匹配情况 user-agent: googlebot-news (group 1) user-agent: *(group 2) user-agent: googlebot (group 3) 以下为抓取工具选择相关组的方法 :
缓存Google 通常会将 robots.txt 文件的内容最多缓存 24 小时, disallow 指令的值区分大小写。所有抓取工具都可以追踪它们。 用法: disallow: [path] allow allow 指令用来指定相应抓取工具可以访问的路径 。抓取工具会使用标准 RETR (RETRIEVE) 命令 ,其他组会被忽略。而忽略其他所有内容。其中包含关于哪些抓取工具可以访问网站的哪些部分的规则。 robots.txt 文件中列出的规则只适用于该文件所在的主机、该值区分大小写。 例如: 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 行, 特定于用户代理的组和全局组 (*) 不会合并。下表总结了 Googlebot 针对各种 HTTP 状态代码处理 robots.txt 文件的方式
。 | ||||||||||||||||||||||||||||||||||
