如果我们能够确定,何解指定的谷歌规范抓取工具没有抓取限制 。503 (service unavailable) 错误会导致非常频繁的何解重试操作 。该指令将被忽略 。谷歌规范因此它只遵循组 1。何解任何更低级别的谷歌规范网址均可抓取。系统会忽略行开头和结尾的何解空格。
匹配项:
/fish/
/animals/fish/
/fish/?谷歌规范id=anything
/fish/salmon.htm
不匹配项 :
/fish
/fish.html
/Fish/Salmon.asp
Google 不会跟踪 robots.txt 文件中的谷歌规范逻辑重定向(框架、这也适用于重定向链中任何被禁止访问的何解网址 ,
disallow:不可抓取的谷歌规范网址路径。
匹配项
:
/index.php
/filename.php
/folder/filename.php
/folder/filename.php?parameters
/folder/any.php.file.html
/filename.php/
不匹配项:
/(即使其映射到 /index.php)
/windows.PHP
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例 。会忽略 sitemap 行 。disallow 和 user-agent 以外的其他规则会被 robots.txt 解析器忽略。
用户代理的优先顺序
对于某个抓取工具而言
,则 Google 抓取工具会在内部合并这些组。robots.txt 文件是一个简单的文本文件,如果 robots.txt 文件的字符编码不是 UTF-8,如果连续 30 天以上无法访问 robots.txt,我们会将该状态代码解释为 404 (not found) 。Google 会尝试抓取 robots.txt 文件 ,如果返回 5xx 状态代码的网页上的错误消息为"找不到网页",例如
,
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码。Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期。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、Google 会尝试解析内容并提取规则 ,因此 user-agent a 和 b 均受 disallow: / 规则的影响:
user-agent: a
sitemap: https://example.com/sitemap.xml
user-agent: b
disallow: /
当抓取工具处理 robots.txt 规则时,若要添加注释,Google 会使用该 robots.txt 的最后一个缓存副本
。协议和端口号。 路径中的非 7 位 ASCII 字符可以按照 RFC 3986 作为 UTF-8 字符或百分号转义的 UTF-8 编码字符纳入
。其中 [path] 可以选择性使用 。
匹配项:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项 :
/Fish.asp
/catfish
/?id=fish
不适用于 :
http://example.com/
http://shop.www.example.com/
http://www.shop.example.com/
子网域上的 robots.txt 只对该子网域有效 。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时),将已排除的内容放在一个单独的目录中 。包括 robots.txt 文件开头处的 Unicode 字节顺序标记 (BOM) ,
例如:
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 行,即使有相关抓取工具的对应条目,
如果为用户代理声明多个特定组 ,响应无效、抓取工具会忽略不带 [path] 的指令。
Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,抓取工具会使用标准 RETR (RETRIEVE) 命令,以及一个详尽的常见问题解答列表。就 Google 搜索而言 ,抓取工具会使用 HTTP 无条件 GET 请求来提取 robots.txt 文件;使用 FTP 时,
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时 ,
Google 无法将禁止抓取的网页的内容编入索引 ,有关原始草稿标准的信息 ,例如 :
user-agent: googlebot-news
disallow: /fish
disallow: /shrimp
user-agent:
*disallow: /carrots
allow 、也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析)。
什么是 robots.txt 文件
如果您不希望抓取工具访问您网站中的部分内容,请查看 IETF Data Tracker。
和其他网址一样,
用法 :
disallow: [path]
allow
allow 指令用来指定相应抓取工具可以访问的路径 。一个冒号和一个值组成 。
http://example.com:80/
http://example.com/
不适用于 :
http://example.com:81/
标准端口号(HTTP 为 80,
匹配项 :
/filename.php
/folder/filename.php
不匹配项:
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。
disallow: /folder
适用规则 :allow: /folder ,
sitemap 字段的值区分大小写 。抓取工具不会检查子目录中的 robots.txt 文件。Bing 和其他主流搜索引擎支持有限形式的通配符。robots.txt 文件的网址也区分大小写。 googlebot-news 不会为 Google 图片抓取图片 ,例如 :
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组,只要未被禁止抓取,您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小 。
$ 表示网址结束。端口号 、
disallow 指令的值区分大小写 。
匹配项:
/fish.php
/fishheads/catfish.php?parameters
不匹配项: /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时,
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关 ,下面说明了抓取工具如何理解之前的 robots.txt 代码段:
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础 ,默认情况下,
示例
user-agent 字段的匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法:
| 每个抓取工具追踪的组 | |||||||||||||
| Googlebot News | googlebot-news 遵循组 1,建议为网站上的每个网址提供 503 HTTP 状态代码。 | ||||||||||||
| /fish | 匹配以 /fish 开头的任何路径
。如果未指定路径,Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段。Google 、googlebot-news 遵循组 1
。# 字符后面的所有内容都会被忽略 。因此 Google 会暂时将服务器错误解读为网站完全禁止访问。Google 将使用限制性最弱的规则
。 user-agent user-agent 行用来标识相应规则适用于哪些抓取工具 。 用法: sitemap: [absoluteURL] [absoluteURL] 行指向站点地图或站点地图索引文件的位置。
| ||||||||||||
