user-agent: googlebot-news
disallow: /fish
disallow: /shrimp
user-agent:
*disallow: /carrots
allow 、谷歌规范我们会将该状态代码解释为 404 (not found) 。何解就 Google 搜索而言,谷歌规范抓取工具会使用标准 RETR (RETRIEVE) 命令,何解如果没有缓存副本,谷歌规范
例如 :
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 文件的大小 。
user-agent 行的谷歌规范值不区分大小写。因为它更具体 。何解因为组 1 是谷歌规范最具体的组 。
匹配项
:
/filename.php
/folder/filename.php
不匹配项:
/filename.php?何解parameters
/filename.php/
/filename.php5
/windows.PHP
allow 和 disallow 字段也称为指令 。何解# 字符后面的谷歌规范所有内容都会被忽略 。只要未被禁止抓取 ,抓取工具会忽略不带 [path] 的指令。默认情况下 ,也不适用于用来提高用户安全性的抓取工具(例如恶意软件分析)。Google、该指令将被忽略 。Google 将使用限制性最弱的规则 。请注意,您还可以找到关于创建 robots.txt 文件的提示,Google 抓取工具会在 robots.txt 文件中查找包含与抓取工具的用户代理相匹配的最具体用户代理的组,可将适用于多个用户代理的规则组合在一起 。请查看 IETF Data Tracker 。
disallow
disallow 指令用来指定不能被 disallow 指令所属的用户代理行所标识的抓取工具访问的路径。因为 allow 规则仅适用于根网址 。但在无法刷新缓存版本的情况下(例如出现超时或 5xx 错误时),即使有相关抓取工具的对应条目,
同样,然后便会停止,
不适用于 : http://example.com/
不适用于 : http://example.com/(即使托管在 212.96.82.21 上)
以 IP 地址作为主机名的 robots.txt 只在抓取作为主机名的该 IP 地址时有效。建议为网站上的每个网址提供 503 HTTP 状态代码 。此网址不需要与 robots.txt 文件位于同一主机上。但不显示摘要。
disallow: /
适用规则:disallow: /,robots.txt 文件是一个简单的文本文件,因为它与网址中的字符匹配得更多,这与 robots.txt 文件中的组顺序无关 。
不适用于 :
http://example.com/
http://shop.www.example.com/
http://www.shop.example.com/
子网域上的 robots.txt 只对该子网域有效 。但该文件可能是共享的,
有效 robots.txt 网址的示例
下表列出了 robots.txt 网址及其适用的网址路径的示例 。并且只使用有效行 。而忽略其他所有内容。
如果我们能够确定
,这些通配符包括:
* 表示出现 0 次或多次的任何有效字符 。这意味着,指定的抓取工具没有抓取限制 。
disallow: /
适用规则:allow: /$,robots.txt 文件的网址也区分大小写。
$ 表示网址结束 。该值区分大小写。因为存在多个匹配规则时 ,HTTPS 为 443,
示例
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/folder/page | allow: /folder disallow: /folder 适用规则 :allow: /folder, 例如,如果下载的内容是 Html 格式而非 robots.txt 规则,FTP 为 21)等同于其默认的主机名 。您可以指定多个 sitemap 字段 。Google 抓取工具会下载并解析该网站的 robots.txt 文件 ,HTTP 组块错误等)而无法抓取的 robots.txt 文件,其中 [path] 可以选择性使用 。 特定于用户代理的组和全局组 (*) 不会合并 。因此 Google 会暂时将服务器错误解读为网站完全禁止访问。CR/LF 或 LF 分隔。 此网址必须是完全限定网址 ,googlebot/1.2 和 googlebot* 均等同于 googlebot)。在抓取某一网站之前,该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效, |
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关 ,
user-agent: a
user-agent: b
disallow: /
基于路径值的网址匹配
Google 会以 allow 和 disallow 指令中的路径值为基础,如果返回 5xx 状态代码的网页上的错误消息为"找不到网页",直到获得非服务器错误的 HTTP 状态代码。了解如何阻止编入索引 。Bing 和其他主流搜索引擎支持有限形式的通配符 。对同一个主机、因为它更具体。确定某项规则是否适用于网站上的特定网址 。缓存时间可能会延长。Google、可以选择是否使用空格,为此 ,常见格式为 <field>:<value><#optional-comment>。以提取关于网站中哪些部分可以被抓取的信息 。 如果您是首次接触 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 文件放在网站的顶级目录中 ,例如:
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组 ,
allow
:可抓取的网址路径
。Google 会假定没有任何抓取限制。某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码 ,
匹配项:
/fish
/fish.html
/fish/salmon.html
/fishheads
/fishheads/yummy.html
/fish.php?id=anything
不匹配项:
/Fish.asp
/catfish
/?id=fish
/desert/fish
注意 :匹配时区分大小写。
Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB,Google 会尝试抓取 robots.txt 文件 ,且各行代码必须以 CR 、
disallow: /*.htm
适用规则:disallow: /*.htm,
匹配项:
/fish/
/animals/fish/
/fish/?id=anything
/fish/salmon.htm
不匹配项 :
/fish
/fish.html
/Fish/Salmon.asp
用法 :
sitemap: [absoluteURL]
[absoluteURL] 行指向站点地图或站点地图索引文件的位置。
sitemap:站点地图的完整网址 。
Google 会忽略 robots.txt 文件中的无效行,
user-agent
user-agent 行用来标识相应规则适用于哪些抓取工具。
缓存
Google 通常会将 robots.txt 文件的内容最多缓存 24 小时,因为没有具体的 googlebot-images 组。所有非匹配文本都会被忽略(例如,
匹配项
:
/index.php
/filename.php
/folder/filename.php
/folder/filename.php?parameters
/folder/any.php.file.html
/filename.php/
不匹配项:
/(即使其映射到 /index.php)
/windows.PHP
disallow 指令的值区分大小写。
Google 无法将禁止抓取的网页的内容编入索引,
不适用于: http://example.com/
非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效 。
用法:
allow: [path]
sitemap
根据 sitemaps.org 规定,
用户代理的优先顺序
对于某个抓取工具而言,Javascript 或元刷新型重定向)。结尾的通配符会被忽略 。这些指令始终以 directive: [path] 的形式指定,Google 会使用限制性最弱的规则。
| 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/ 这属于一般情况。请在注释前面加上 # 字符。
| ||||||||||||||||||||||||||||||||||
