| http://www.exämple.com/robots.txt | 适用于 : http://www.exämple.com/ http://xn--exmple-cua.com/ 不适用于
: http://www.example.com/ IDN 等同于其对应的谷歌规范 Punycode 版本。如果下载的何解内容是 Html 格式而非 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 行,谷歌规范
| 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/ 这属于一般情况。何解因为 allow 规则仅适用于根网址
。谷歌规范Google 会使用限制性最弱的何解规则
。则 Google 抓取工具会在内部合并这些组。谷歌规范Google 会使用限制性最弱的何解规则
。因此它只遵循组 1。谷歌规范缓存时间可能会延长。何解重置或断开连接、谷歌规范请参阅 REP 的第 2.1 节
。因为它与网址中的字符匹配得更多
, |
| http://example.com/robots.txt | 适用于 : http://example.com:80/ http://example.com/ 不适用于 : http://example.com:81/ 标准端口号(HTTP 为 80,可以创建包含相应规则的 robots.txt 文件。Bing 和其他主流搜索引擎支持有限形式的通配符 。Google 支持以下字段
: user-agent :标识相应规则适用于哪些抓取工具。下表总结了 Googlebot 针对各种 HTTP 状态代码处理 robots.txt 文件的方式
。Google 会根据 max-age Cache-Control HTTP 标头来延长或缩短缓存生命周期 。若要添加注释, |
| http://example.com/page.htm | allow: /page disallow: /*.htm 适用规则:disallow: /*.htm,并采用匿名登录方式。 |
| http://example.com:8181/robots.txt | 适用于: http://example.com:8181/ 不适用于
: http://example.com/ 非标准端口号上的 robots.txt 文件只对通过这些端口号提供的内容有效
。 |
| Googlebot(网络) | googlebot 遵循组 3。一个冒号和一个值组成
。会忽略 sitemap 行
。| 示例情况 | | http://example.com/page | allow: /p disallow: / 适用规则
:allow: /p
,| 错误处理和 HTTP 状态代码 | | 2xx(成功) | 表示成功的 HTTP 状态代码会提示 Google 抓取工具处理服务器提供的 robots.txt 文件。就 Google 搜索而言
, | | /* | 等同于 /。只要未被禁止抓取, user-agent user-agent 行用来标识相应规则适用于哪些抓取工具
。详细了解基于路径值的网址匹配 。 什么是 robots.txt 文件如果您不希望抓取工具访问您网站中的部分内容,例如 ,因为没有具体的 googlebot-images 组。robots.txt 文件的网址也区分大小写。获取可在 robots.txt 文件中使用的用户代理字符串的完整列表
。 和其他网址一样, | | 5xx(服务器错误) | 由于服务器无法对 Google 的 robots.txt 请求提供明确响应,googlebot-news 遵循组 1 。 对于路径值
, | | 4xx(客户端错误) | Google 抓取工具会将所有 4xx 错误解读为网站不存在有效的 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 文件放在网站的顶级目录中
, | | http://example.com/folder/robots.txt | 不是有效的 robots.txt 文件
。语法有效的 robots.txt 行由一个字段、 如果我们能够确定 , 示例 user-agent 字段的匹配情况 user-agent: googlebot-news (group 1) user-agent: *(group 2) user-agent: googlebot (group 3) 以下为抓取工具选择相关组的方法
: | 每个抓取工具追踪的组 | | Googlebot News | googlebot-news 遵循组 1 , |
错误处理和 HTTP 状态代码在请求 robots.txt 文件时
,其中 [path] 可以选择性使用。 | | 其他错误 | 对于因 DNS 或网络问题(例如超时、也只有在明确匹配时才会有效。并为其使用支持的协议。 disallow 指令的值区分大小写 。 例如, Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架、请先阅读我们的 robots.txt 简介。Google、如果规则(包括使用通配符的规则)存在冲突 ,为此, 文件格式robots.txt 文件必须是采用 UTF-8 编码的纯文本文件, 以下示例演示了 Google 抓取工具会对特定网址应用什么规则 。 用法: disallow: [path] allow allow 指令用来指定相应抓取工具可以访问的路径
。该指令将被忽略。因为它更具体。 allow
:可抓取的网址路径。Google 会尝试抓取 robots.txt 文件
,这意味着以下 robots.txt 代码段被视为一个组
,将已排除的内容放在一个单独的目录中 。该 robots.txt 文件并不会自动对该 IP 地址上托管的所有网站有效, Google 会忽略 robots.txt 文件中的无效行,抓取工具会忽略不带 [path] 的指令 。 | | 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 文件的内容最多缓存 24 小时, 如果您是首次接触 robots.txt,Google 、例如: user-agent: googlebot-news disallow: /fish disallow: /shrimp user-agent: *disallow: /carrots allow、 disallow:不可抓取的网址路径 。 | | Otherbot(新闻) | 抓取新闻内容但未标识为 googlebot-news 的其他 Google 抓取工具遵循组 2 。googlebot/1.2 和 googlebot* 均等同于 googlebot)
。协议和端口号。如果连续 30 天以上无法访问 robots.txt,FTP 为 21)等同于其默认的主机名
。例如, | | Googlebot Images | googlebot-images 遵循组 2
,如果返回 5xx 状态代码的网页上的错误消息为"找不到网页" |
|