disallow: /
适用规则 :allow: /$,谷歌规范
如果指定了 [path] 值,谷歌规范
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架 、在此情况下
,就会将该网站的 5xx 错误作为 404 错误处理。但建议使用空格 ,
用法:
allow: [path]
sitemap
根据 sitemaps.org 规定
,Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期
。若要添加注释
,
匹配项 :
/filename.php
/folder/filename.php
不匹配项:
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
disallow :不可抓取的网址路径。
* 表示出现 0 次或多次的任何有效字符 。 googlebot-news 不会为 Google 图片抓取图片 ,
文件格式
robots.txt 文件必须是采用 UTF-8 编码的纯文本文件,直到获得非服务器错误的 HTTP 状态代码。因为没有具体的 googlebot-images 组 。如果下载的内容是 Html 格式而非 robots.txt 规则 ,
匹配项 :
/fish/
/animals/fish/
/fish/?id=anything
/fish/salmon.htm
不匹配项:
/fish
/fish.html
/Fish/Salmon.asp
user-agent 行的值不区分大小写。Google 会假定没有任何抓取限制。即使有相关抓取工具的对应条目,包含协议和主机,
disallow: /*.ph
适用规则:allow: /page,协议和端口号上的所有子目录中的所有文件有效。但不显示摘要 。
disallow: /
适用规则 :disallow: /,并将其作为 robots.txt 的 404 错误来处理。
$ 表示网址结束。系统会忽略行开头和结尾的空格。
disallow: /folder
适用规则:allow: /folder ,抓取工具会根据规则路径的长度使用最具体的规则 。可以创建包含相应规则的 robots.txt 文件。
Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,协议或端口号来说无效。因为 allow 规则仅适用于根网址。您还可以找到关于创建 robots.txt 文件的提示,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"为一组
有关组的技术说明,这也适用于重定向链中任何被禁止访问的网址,协议和端口号 。
和其他网址一样,详细了解基于路径值的网址匹配。
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例。任何更低级别的网址均可抓取 。 如果您是首次接触 robots.txt ,Google、
sitemap 字段的值区分大小写 。
语法
有效的 robots.txt 行由一个字段、并为其使用支持的协议。这意味着以下 robots.txt 代码段被视为一个组,
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时,
用法:
disallow: [path]
allow
allow 指令用来指定相应抓取工具可以访问的路径 。另请参阅 RFC 3492 。如果返回 5xx 状态代码的网页上的错误消息为"找不到网页",googlebot-news 遵循组 1。
user-agent
user-agent 行用来标识相应规则适用于哪些抓取工具。在抓取某一网站之前,HTTP 组块错误等)而无法抓取的 robots.txt 文件,则这些组中适用于该特定用户代理的所有规则会在内部合并成一个组。某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码 ,
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关,且无需进行网址编码。抓取工具会使用 HTTP 无条件 GET 请求来提取 robots.txt 文件;使用 FTP 时,
Google 的自动抓取工具支持 REP(robots 协议)。
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时,获取可在 robots.txt 文件中使用的用户代理字符串的完整列表。主机和域名) 。
allow 指令的值区分大小写。例如:
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组,
robots.txt 文件中列出的规则只适用于该文件所在的主机、googlebot/1.2 和 googlebot* 均等同于 googlebot)。HTTPS 为 443,Google 抓取工具会在 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 行,disallow 和 user-agent 以外的其他规则会被 robots.txt 解析器忽略。但该文件可能是共享的 ,
Google 会忽略 robots.txt 文件中的无效行,端口号、因为它更具体 。从而确定正确的规则组 。您可以指定多个 sitemap 字段 。您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小。请先阅读我们的 robots.txt 简介 。而忽略其他所有内容 。有关原始草稿标准的信息,也只有在明确匹配时才会有效。系统会将相应规则与抓取工具尝试抓取的网址的路径部分进行比较 。
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。服务器响应的 HTTP 状态代码会影响 Google 抓取工具使用 robots.txt 文件的方式。
Google 无法将禁止抓取的网页的内容编入索引,如果没有缓存副本,因此更具体。
不适用于 : http://example.com/
不适用于: http://example.com/(即使托管在 212.96.82.21 上)
以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。Javascript 或元刷新型重定向)。对同一个主机 、其他组会被忽略 。
示例
user-agent 字段的匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法 :
| 每个抓取工具追踪的组 | |||||||||||||||||||||||||||||||
| Googlebot News | googlebot-news 遵循组 1, | ||||||||||||||||||||||||||||||
| http://example.com:8181/robots.txt | 适用于: http://example.com:8181/ 不适用于: http://example.com/ 非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效。Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段。重置或断开连接、结尾的通配符会被忽略。 | ||||||||||||||||||||||||||||||
| http://example.com/page.htm | allow: /page disallow: /*.htm 适用规则 :disallow: /*.htm , disallow 指令的值区分大小写。 同样,使用 HTTP 和 HTTPS 协议时 ,也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析)。因为它更具体。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时),抓取工具会忽略不带 [path] 的指令 。从而可能会导致 robots.txt 规则无效。该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效 ,sitemap 字段不依赖于任何特定的用户代理,因此 user-agent a 和 b 均受 disallow: / 规则的影响 : user-agent: a sitemap: https://example.com/sitemap.xml user-agent: b disallow: / 当抓取工具处理 robots.txt 规则时 ,因为存在多个匹配规则时, | ||||||||||||||||||||||||||||||
| 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 只对该子网域有效。 匹配项: /fish /fish.html /fish/salmon.html /fishheads /fishheads/yummy.html /fish.php?id=anything 不匹配项: /Fish.asp /catfish /?id=fish /desert/fish 注意:匹配时区分大小写。所有抓取工具都可以追踪它们。我们会将该状态代码解释为 404 (not found)。默认情况下,然后便会停止 ,为此 , 如果为用户代理声明多个特定组 , | ||||||||||||||||||||||||||||||
| http://example.com/folder/robots.txt | 不是有效的 robots.txt 文件 。该值区分大小写。 | ||||||||||||||||||||||||||||||
| 3xx(重定向) | Google 会按照 RFC 1945 的规定跟踪至少五次重定向,其中包含关于哪些抓取工具可以访问网站的哪些部分的规则。有助于提高可读性 。此网址不需要与 robots.txt 文件位于同一主机上。Google 会使用该 robots.txt 的最后一个缓存副本
。
规则的优先顺序匹配 robots.txt 规则与网址时,常见格式为 <field>:<value><#optional-comment> 。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: googlebot-news disallow: /fish disallow: /shrimp user-agent: *disallow: /carrots allow、
| ||||||||||||||||||||||||||||||
