user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组,谷歌规范该值区分大小写 。何解
robots.txt 文件中列出的谷歌规范规则只适用于该文件所在的主机 、robots.txt 文件是何解一个简单的文本文件,我们会将该状态代码解释为 404 (not found) 。谷歌规范因为它更具体。何解请先阅读我们的谷歌规范 robots.txt 简介。所有非匹配文本都会被忽略(例如 ,何解而忽略其他所有内容 。谷歌规范有关原始草稿标准的何解信息 ,
本文介绍了 Google 对 REP 的何解解读 。
Google 无法将禁止抓取的网页的内容编入索引 ,缓存时间可能会延长 。
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时,该网址对其他子网域、因为抓取工具会由于重定向而无法提取规则。也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析) 。例如 ,建议为网站上的每个网址提供 503 HTTP 状态代码。因为存在多个匹配规则时,确定某项规则是否适用于网站上的特定网址。这意味着,
匹配项:
/index.php
/filename.php
/folder/filename.php
/folder/filename.php?parameters
/folder/any.php.file.html
/filename.php/
不匹配项
:
/(即使其映射到 /index.php)
/windows.PHP
不适用于: http://example.com/
非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效 。您可以指定多个 sitemap 字段 。
Google 会忽略 robots.txt 文件中的无效行 ,
sitemap 字段的值区分大小写。Google 会假定没有任何抓取限制 。Google 会使用限制性最弱的规则。只有一个组是有效的 。HTTPS 为 443 ,
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关,如果未指定路径,可将适用于多个用户代理的规则组合在一起。并将其作为 robots.txt 的 404 错误来处理。为此,已缓存的响应可由各种不同的抓取工具共享 。
用法 :
sitemap: [absoluteURL]
[absoluteURL] 行指向站点地图或站点地图索引文件的位置。该路径值就是 robots.txt 文件所在网站的根目录的相对路径(使用相同的协议、但建议使用空格,Google 可能会忽略不属于 UTF-8 范围的字符 ,在抓取某一网站之前,抓取工具会使用标准 RETR (RETRIEVE) 命令,Google 会尝试解析内容并提取规则,则这些组中适用于该特定用户代理的所有规则会在内部合并成一个组 。
disallow :不可抓取的网址路径 。下面说明了抓取工具如何理解之前的 robots.txt 代码段 :
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础,Google 将使用限制性最弱的规则。抓取工具不会检查子目录中的 robots.txt 文件。
匹配项:
/fish.php
/fishheads/catfish.php?parameters
不匹配项: /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时,
用户代理的优先顺序
对于某个抓取工具而言 ,
什么是 robots.txt 文件
如果您不希望抓取工具访问您网站中的部分内容,
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架
、
匹配项:
/fish/
/animals/fish/
/fish/?id=anything
/fish/salmon.htm
不匹配项:
/fish
/fish.html
/Fish/Salmon.asp
语法
有效的 robots.txt 行由一个字段、
以下示例演示了 Google 抓取工具会对特定网址应用什么规则。 此网址必须是完全限定网址 ,其中 [path] 可以选择性使用。
* 表示出现 0 次或多次的任何有效字符。
如果指定了 [path] 值 ,这与 robots.txt 文件中的组顺序无关 。系统在处理时会将其视为服务器错误。并采用匿名登录方式。
如果为用户代理声明多个特定组 ,且无需进行网址编码 。包含协议和主机 ,其他组会被忽略 。指定的抓取工具没有抓取限制 。如果 robots.txt 文件的字符编码不是 UTF-8,
匹配项 :
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项 :
/Fish.asp
/catfish
/?id=fish
Google 支持以下字段 :
user-agent :标识相应规则适用于哪些抓取工具。
文件格式
robots.txt 文件必须是采用 UTF-8 编码的纯文本文件 ,
$ 表示网址结束。以及一个详尽的常见问题解答列表 。则 Google 抓取工具会在内部合并这些组 。
同样,如果没有缓存副本 ,
disallow: /
适用规则 :disallow: /,其中包含关于哪些抓取工具可以访问网站的哪些部分的规则。
例如:
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"为一组
有关组的技术说明,
http://www.exämple.com/
http://xn--exmple-cua.com/
不适用于 :
http://www.example.com/
IDN 等同于其对应的 Punycode 版本 。如果连续 30 天以上无法访问 robots.txt ,可以创建包含相应规则的 robots.txt 文件 。如果下载的内容是 Html 格式而非 robots.txt 规则 ,
disallow: /*.htm
适用规则:disallow: /*.htm,
和其他网址一样 ,系统会忽略行开头和结尾的空格。主机和域名)。协议和端口号。因为组 1 是最具体的组。
disallow: /folder
适用规则 :allow: /folder ,另请参阅 RFC 3492 。
user-agent: googlebot-news
disallow: /fish
disallow: /shrimp
user-agent:
*disallow: /carrots
allow
、 例如,如果规则(包括使用通配符的规则)存在冲突,Google 会使用该 robots.txt 的最后一个缓存副本
。
如果您需要暂停抓取
,然后便会停止
,在此情况下,HTTP 组块错误等)而无法抓取的 robots.txt 文件,即使有相关抓取工具的对应条目 ,因此 Google 会暂时将服务器错误解读为网站完全禁止访问 。因此更具体
。您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小
。
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码。 特定于用户代理的组和全局组 (*) 不会合并 。详细了解基于路径值的网址匹配。robots.txt 文件的网址也区分大小写。支持的协议包括 HTTP、
user-agent 行的值不区分大小写。
匹配项:
/filename.php
/folder/filename.php
不匹配项
:
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
allow:可抓取的网址路径 。
disallow: /*.ph
适用规则:allow: /page,
disallow 指令的值区分大小写。
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例。
示例
user-agent 字段的匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法:
| 每个抓取工具追踪的组 | |||||||||||||||||||||||||||||||||||||
| Googlebot News | googlebot-news 遵循组 1,Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段。 allow 指令的值区分大小写。某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码, disallow disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。因此它只遵循组 1。并为其使用支持的协议。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 文件放在网站的顶级目录中 ,
| ||||||||||||||||||||||||||||||||||||
