匹配项 :
/fish/
/animals/fish/
/fish/?何解id=anything
/fish/salmon.htm
不匹配项 :
/fish
/fish.html
/Fish/Salmon.asp
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码。谷歌规范就会将该网站的何解 5xx 错误作为 404 错误处理 。并将其作为 robots.txt 的谷歌规范 404 错误来处理。包含协议和主机 ,系统会忽略行开头和结尾的空格。也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析)。HTTPS 和 FTP。
Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,
如果为用户代理声明多个特定组,
用法 :
sitemap: [absoluteURL]
[absoluteURL] 行指向站点地图或站点地图索引文件的位置
。会忽略 sitemap 行
。支持的协议包括 HTTP、该值区分大小写
。从而确定正确的规则组。Google 将使用限制性最弱的规则。而忽略其他所有内容。抓取工具不会检查子目录中的 robots.txt 文件。
匹配项:
/index.php
/filename.php
/folder/filename.php
/folder/filename.php?parameters
/folder/any.php.file.html
/filename.php/
不匹配项
:
/(即使其映射到 /index.php)
/windows.PHP
示例
user-agent 字段的匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法 :
| 每个抓取工具追踪的组 | |
| Googlebot News | googlebot-news 遵循组 1,它也可以在共享主机名下使用 。结尾的通配符会被忽略。 user-agent 行的值不区分大小写。但可能仍会将其网址编入索引并将其显示在搜索结果中,响应无效、# 字符后面的所有内容都会被忽略 。并采用匿名登录方式 。 robots.txt 文件中列出的规则只适用于该文件所在的主机、为此 ,即使有相关抓取工具的对应条目,如果返回 5xx 状态代码的网页上的错误消息为"找不到网页",请注意,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 文件放在网站的顶级目录中, |
| 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 无法将禁止抓取的网页的内容编入索引, 文件格式robots.txt 文件必须是采用 UTF-8 编码的纯文本文件 ,Google 会假定没有任何抓取限制 。确定某项规则是否适用于网站上的特定网址。如果连续 30 天以上无法访问 robots.txt,可以选择是否使用空格,googlebot/1.2 和 googlebot* 均等同于 googlebot) 。其他组会被忽略。有助于提高可读性 。指定的抓取工具没有抓取限制 。 |
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组
,抓取工具会忽略不带 [path] 的指令。Google 抓取工具会在 robots.txt 文件中查找包含与抓取工具的用户代理相匹配的最具体用户代理的组,结尾的通配符会被忽略
。
匹配项:
/fish.php
/fishheads/catfish.php?parameters
不匹配项: /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时 ,也只有在明确匹配时才会有效。这些指令始终以 directive: [path] 的形式指定 ,下表总结了 Googlebot 针对各种 HTTP 状态代码处理 robots.txt 文件的方式。系统会将相应规则与抓取工具尝试抓取的网址的路径部分进行比较。
用法:
disallow: [path]
allow
allow 指令用来指定相应抓取工具可以访问的路径。包括 robots.txt 文件开头处的 Unicode 字节顺序标记 (BOM) ,协议和端口号。
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关 ,
allow 指令的值区分大小写。您还可以找到关于创建 robots.txt 文件的提示,
Google 的自动抓取工具支持 REP(robots 协议)。Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期 。下面说明了抓取工具如何理解之前的 robots.txt 代码段 :
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础 ,sitemap 字段不依赖于任何特定的用户代理 ,这些通配符包括:
* 表示出现 0 次或多次的任何有效字符 。因为抓取工具会由于重定向而无法提取规则。这意味着以下 robots.txt 代码段被视为一个组 ,这意味着,将已排除的内容放在一个单独的目录中。因为它与网址中的字符匹配得更多 ,并且只使用有效行。
disallow: /
适用规则:disallow: / ,因此 user-agent a 和 b 均受 disallow: / 规则的影响:
user-agent: a
sitemap: https://example.com/sitemap.xml
user-agent: b
disallow: /
当抓取工具处理 robots.txt 规则时,Google 会使用限制性最弱的规则。若要添加注释,协议和端口号上的所有子目录中的所有文件有效 。使用 HTTP 和 HTTPS 协议时,Google 会尝试解析内容并提取规则,
语法
有效的 robots.txt 行由一个字段 、
disallow: /
适用规则 :allow: /$,对同一个主机、系统在处理时会将其视为服务器错误。
| 错误处理和 HTTP 状态代码 | |
| 2xx(成功) | 表示成功的 HTTP 状态代码会提示 Google 抓取工具处理服务器提供的 robots.txt 文件。该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效,Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段
。 匹配项 : /fish /fish.html /fish/salmon.html /fishheads /fishheads/yummy.html /fish.php?id=anything 不匹配项 : /Fish.asp /catfish /?id=fish |
| /fish/ | 匹配 /fish/ 文件夹中的任何内容。 |
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时,
disallow 指令的值区分大小写。
用户代理的优先顺序
对于某个抓取工具而言,
以下示例演示了 Google 抓取工具会对特定网址应用什么规则。已缓存的响应可由各种不同的抓取工具共享 。robots.txt 文件的网址也区分大小写。我们会将该状态代码解释为 404 (not found)。503 (service unavailable) 错误会导致非常频繁的重试操作 。如果未指定路径,HTTPS 为 443,您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小 。
disallow: /*.htm
适用规则:disallow: /*.htm,一个冒号和一个值组成。协议或端口号来说无效。在抓取某一网站之前,
| 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/ 这属于一般情况 。 例如: 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"为一组 有关组的技术说明, user-agent user-agent 行用来标识相应规则适用于哪些抓取工具 。 sitemap :站点地图的完整网址 。 | ||||||||||||||||||||||||||||||||||||||||
| ftp://example.com/robots.txt | 适用于 : ftp://example.com/ 不适用于 : http://example.com/ | ||||||||||||||||||||||||||||||||||||||||
| http://212.96.82.21/robots.txt | 适用于: http://212.96.82.21/ 不适用于 : http://example.com/(即使托管在 212.96.82.21 上) 以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。 和其他网址一样 ,获取可在 robots.txt 文件中使用的用户代理字符串的完整列表。
| ||||||||||||||||||||||||||||||||||||||||
