什么是谷歌规范 robots.txt 文件
如果您不希望抓取工具访问您网站中的部分内容 ,为此,何解这也适用于重定向链中任何被禁止访问的谷歌规范网址,
用法:
allow: [path]
sitemap
根据 sitemaps.org 规定 ,何解已缓存的谷歌规范响应可由各种不同的抓取工具共享。 此网址必须是何解完全限定网址 ,就 Google 搜索而言 ,谷歌规范端口号 、何解
$ 表示网址结束 。何解
disallow: /
适用规则:allow: /$ ,谷歌规范也只有在明确匹配时才会有效 。何解下面说明了抓取工具如何理解之前的谷歌规范 robots.txt 代码段:
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础,
http://example.com:80/
http://example.com/
不适用于 :
http://example.com:81/
标准端口号(HTTP 为 80,
Google 会忽略 robots.txt 文件中的无效行,
disallow 指令的值区分大小写 。
匹配项 :
/fish/
/animals/fish/
/fish/?id=anything
/fish/salmon.htm
不匹配项
:
/fish
/fish.html
/Fish/Salmon.asp
不适用于: http://example.com/
不适用于: http://example.com/(即使托管在 212.96.82.21 上)
以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。
匹配项 :
/index.php
/filename.php
/folder/filename.php
/folder/filename.php?parameters
/folder/any.php.file.html
/filename.php/
不匹配项 :
/(即使其映射到 /index.php)
/windows.PHP
如果我们能够确定 ,
disallow :不可抓取的网址路径 。
| 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/ 这属于一般情况。 对于路径值,但不显示摘要 。 sitemap :站点地图的完整网址 。CR/LF 或 LF 分隔。如果返回 5xx 状态代码的网页上的错误消息为"找不到网页", allow 和 disallow 字段也称为指令。Google 会使用限制性最弱的规则。获取可在 robots.txt 文件中使用的用户代理字符串的完整列表 。即使有相关抓取工具的对应条目 ,Google、请先阅读我们的 robots.txt 简介 。 Google 无法将禁止抓取的网页的内容编入索引 ,Google 抓取工具会在 robots.txt 文件中查找包含与抓取工具的用户代理相匹配的最具体用户代理的组,将已排除的内容放在一个单独的目录中。抓取工具会根据规则路径的长度使用最具体的规则 。有助于提高可读性 。因为没有具体的 googlebot-images 组。直到获得非服务器错误的 HTTP 状态代码 。 |
| Googlebot News(抓取图片时) | 抓取图片时 , |
# 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 a 和 b 均受 disallow: / 规则的影响 :
user-agent: a
sitemap: https://example.com/sitemap.xml
user-agent: b
disallow: /
当抓取工具处理 robots.txt 规则时 ,Google 将使用限制性最弱的规则。
匹配项
:
/fish.php
/fishheads/catfish.php?parameters
不匹配项 : /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时 ,HTTPS 为 443,如果下载的内容是 Html 格式而非 robots.txt 规则 ,这意味着抓取将不受限制。对同一个主机、该值区分大小写。
disallow: /folder
适用规则 :allow: /folder,
匹配项:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项 :
/Fish.asp
/catfish
/?id=fish
同样,
disallow: /*.htm
适用规则:disallow: /*.htm ,REP 不适用于由用户控制的 Google 抓取工具(例如 Feed 订阅),但该文件可能是共享的,可以选择是否使用空格 ,
文件格式
robots.txt 文件必须是采用 UTF-8 编码的纯文本文件
,
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架
、Google 会使用该 robots.txt 的最后一个缓存副本
。
| 错误处理和 HTTP 状态代码 | |
| 2xx(成功) | 表示成功的 HTTP 状态代码会提示 Google 抓取工具处理服务器提供的 robots.txt 文件。因为组 1 是最具体的组。 allow 指令的值区分大小写 。有关原始草稿标准的信息, |
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时,如果 robots.txt 文件的字符编码不是 UTF-8 ,
如果为用户代理声明多个特定组,路径值必须以 / 开头来表示根目录,主机和域名)。
用法:
disallow: [path]
allow
allow 指令用来指定相应抓取工具可以访问的路径。
例如:
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"为一组
有关组的技术说明 ,就会将该网站的 5xx 错误作为 404 错误处理。该网址对其他子网域、
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例。Google 可能会忽略不属于 UTF-8 范围的字符,因此它只遵循组 1。
sitemap 字段的值区分大小写。抓取工具会忽略不含路径的指令。
以下示例演示了 Google 抓取工具会对特定网址应用什么规则 。例如 :
user-agent: googlebot-news
disallow: /fish
disallow: /shrimp
user-agent:
*disallow: /carrots
allow 、
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时,此网址不需要与 robots.txt 文件位于同一主机上 。Google 、
allow :可抓取的网址路径。响应无效、 如果您是首次接触 robots.txt ,某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码 ,确定某项规则是否适用于网站上的特定网址。并为其使用支持的协议。
本文介绍了 Google 对 REP 的解读 。抓取工具会使用 HTTP 无条件 GET 请求来提取 robots.txt 文件;使用 FTP 时 , googlebot-news 不会为 Google 图片抓取图片 ,因为抓取工具会由于重定向而无法提取规则。googlebot-news 遵循组 1。协议和端口号上的所有子目录中的所有文件有效 。以及一个详尽的常见问题解答列表。缓存时间可能会延长 。因为它更具体。
例如:
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 行,您可以指定多个 sitemap 字段。则这些组中适用于该特定用户代理的所有规则会在内部合并成一个组。
Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,系统会忽略行开头和结尾的空格 。
不适用于 :
http://example.com/
http://shop.www.example.com/
http://www.shop.example.com/
子网域上的 robots.txt 只对该子网域有效。因此更具体 。则 Google 抓取工具会在内部合并这些组。它也可以在共享主机名下使用 。您可以通过整合会导致 robots.txt 文件过大的指令来减小 robots.txt 文件的大小 。抓取工具不会检查子目录中的 robots.txt 文件。Javascript 或元刷新型重定向) 。
disallow: /
适用规则 :disallow: / ,请查看 IETF Data Tracker。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时) ,
如果您需要暂停抓取 ,
Google 支持以下字段 :
user-agent:标识相应规则适用于哪些抓取工具。
匹配项:
/filename.php
/folder/filename.php
不匹配项 :
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
disallow: /*.ph
适用规则:allow: /page,
匹配项:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项:
/Fish.asp
/catfish
/?id=fish
/desert/fish
注意:匹配时区分大小写。但建议使用空格,Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期 。该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效,googlebot/1.2 和 googlebot* 均等同于 googlebot)。
不适用于 : http://example.com/
非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效 。Bing 和其他主流搜索引擎支持有限形式的通配符。了解如何阻止编入索引 。
robots.txt 文件中列出的规则只适用于该文件所在的主机、默认情况下 ,
语法
有效的 robots.txt 行由一个字段、但可能仍会将其网址编入索引并将其显示在搜索结果中,详细了解基于路径值的网址匹配。且无需进行网址编码。
和其他网址一样,
如果指定了 [path] 值,
这包括 401 (unauthorized) 和 403 (forbidden) HTTP 状态代码 。HTTP 组块错误等)而无法抓取的 robots.txt 文件
,
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关 ,
| 示例情况 | |||||||||||||
| http://example.com/page | allow: /p disallow: / 适用规则:allow: /p,
| ||||||||||||
