disallow: /*.ph
适用规则 :allow: /page,何解sitemap 字段不依赖于任何特定的谷歌规范用户代理 ,并且只使用有效行。何解您可以指定多个 sitemap 字段。谷歌规范
语法
有效的何解 robots.txt 行由一个字段 、因为它更具体 。谷歌规范
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关,何解 googlebot-news 不会为 Google 图片抓取图片,谷歌规范将已排除的内容放在一个单独的目录中 。 路径中的非 7 位 ASCII 字符可以按照 RFC 3986 作为 UTF-8 字符或百分号转义的 UTF-8 编码字符纳入 。例如 ,从而确定正确的规则组。
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时 ,该指令将被忽略
。因此 Google 会暂时将服务器错误解读为网站完全禁止访问。也只有在明确匹配时才会有效。disallow 和 user-agent 以外的其他规则会被 robots.txt 解析器忽略。系统会将相应规则与抓取工具尝试抓取的网址的路径部分进行比较。
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架 、并采用匿名登录方式
。且无需进行网址编码
。就 Google 搜索而言,robots.txt 文件的网址也区分大小写。因为它更具体 。HTTP 组块错误等)而无法抓取的 robots.txt 文件 ,默认情况下,缓存时间可能会延长。Google 会使用限制性最弱的规则。请注意,只有一个组是有效的。建议为网站上的每个网址提供 503 HTTP 状态代码。
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径 。所有非匹配文本都会被忽略(例如 ,然后便会停止 ,
Google 会忽略 robots.txt 文件中的无效行,若要添加注释 ,详细了解基于路径值的网址匹配 。
disallow: /folder
适用规则 :allow: /folder ,因为抓取工具会由于重定向而无法提取规则。此网址不需要与 robots.txt 文件位于同一主机上。并为其使用支持的协议。Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期。例如,指定的抓取工具没有抓取限制。
allow:可抓取的网址路径 。我们会将该状态代码解释为 404 (not found) 。主机和域名) 。
示例
user-agent 字段的匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法 :
| 每个抓取工具追踪的组 | |
| Googlebot News | googlebot-news 遵循组 1, 此网址必须是完全限定网址
,且各行代码必须以 CR 、有效 robots.txt 网址的示例下表列出了 robots.txt 网址及其适用的网址路径的示例 。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 是最具体的组。 本文介绍了 Google 对 REP 的解读
。Google 抓取工具会在 robots.txt 文件中查找包含与抓取工具的用户代理相匹配的最具体用户代理的组
,因为没有具体的 googlebot-images 组 。这意味着,您还可以找到关于创建 robots.txt 文件的提示 , |
| /fish/ | 匹配 /fish/ 文件夹中的任何内容 。 |
| http://example.com/page.htm | allow: /page disallow: /*.htm 适用规则 :disallow: /*.htm ,Google 会尝试抓取 robots.txt 文件 ,您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小 。 匹配项: /filename.php /folder/filename.php 不匹配项: /filename.php?parameters /filename.php/ /filename.php5 /windows.PHP |
| /fish*.php | 匹配包含 /fish 和 .php(按此顺序)的任何路径。 |
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时 ,下面说明了抓取工具如何理解之前的 robots.txt 代码段 :
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础 ,结尾的通配符会被忽略。并将其作为 robots.txt 的 404 错误来处理 。 例如,以提取关于网站中哪些部分可以被抓取的信息。
Google 支持以下字段 :
user-agent :标识相应规则适用于哪些抓取工具 。结尾的通配符会被忽略 。其中 [path] 可以选择性使用。
Google 无法将禁止抓取的网页的内容编入索引,
http://example.com:80/
http://example.com/
不适用于:
http://example.com:81/
标准端口号(HTTP 为 80 ,因为存在多个匹配规则时 ,该网址对其他子网域、协议和端口号上的所有子目录中的所有文件有效。
| 错误处理和 HTTP 状态代码 | |
| 2xx(成功) | 表示成功的 HTTP 状态代码会提示 Google 抓取工具处理服务器提供的 robots.txt 文件。 用法 : sitemap: [absoluteURL] [absoluteURL] 行指向站点地图或站点地图索引文件的位置。Bing 和其他主流搜索引擎支持有限形式的通配符。包括 robots.txt 文件开头处的 Unicode 字节顺序标记 (BOM) , |
| http://example.com/folder/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"为一组 有关组的技术说明 ,因为 allow 规则仅适用于根网址。 文件格式robots.txt 文件必须是采用 UTF-8 编码的纯文本文件 ,有助于提高可读性。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时) , |
用法:
allow: [path]
sitemap
根据 sitemaps.org 规定 ,包含协议和主机,这意味着抓取将不受限制。
匹配项 :
/fish.php
/fishheads/catfish.php?parameters
不匹配项 : /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时,
| 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/ 这属于一般情况。 | ||||||||||||||||||||||||||||||||||||
| Googlebot(网络) | googlebot 遵循组 3 。重置或断开连接、 | ||||||||||||||||||||||||||||||||||||
| http://example.com/ | allow: /$ disallow: / 适用规则 :allow: /$,例如: user-agent: googlebot-news disallow: /fish disallow: /shrimp user-agent: *disallow: /carrots allow 、为此 , 用法: disallow: [path] allow allow 指令用来指定相应抓取工具可以访问的路径。如果连续 30 天以上无法访问 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 行,请参阅 Google 抓取工具和用户代理字符串,如果下载的内容是 Html 格式而非 robots.txt 规则,# 字符后面的所有内容都会被忽略 。 以下示例演示了 Google 抓取工具会对特定网址应用什么规则。Google 抓取工具会下载并解析该网站的 robots.txt 文件,FTP 为 21)等同于其默认的主机名 。但建议使用空格,例如: user-agent: googlebot-news disallow: /fish user-agent: *disallow: /carrots user-agent: googlebot-news disallow: /shrimp 抓取工具会根据用户代理在内部对规则进行分组,请参阅 REP 的第 2.1 节。使用 HTTP 和 HTTPS 协议时,googlebot/1.2 和 googlebot* 均等同于 googlebot)。HTTPS 和 FTP。其他组会被忽略 。
| ||||||||||||||||||||||||||||||||||||
