# robots.txt

> robots.txt 告诉爬虫可以抓取哪些 URL 路径，已标准化为 RFC 9309。它只控制抓取，不控制索引。被禁止抓取的 URL 如果有其他页面链接，仍可能在没有内容的情况下被编入索引。

- URL: https://geo.casa/zh-cn/crawling-indexing/robots-txt/
- 参考 · 官方文档已说明
- 审核于: 2026-10-24

## 位置与格式

- 放在每个主机名和协议的根目录 `/robots.txt`（`https://example.com/robots.txt` 不覆盖 `https://shop.example.com/`）。
- 纯文本，UTF-8 编码。每组规则以一行或多行 `user-agent` 开头，后跟 `allow` / `disallow` 规则。

## 支持的字段（Google）

| 字段 | 作用 |
|---|---|
| `user-agent` | 规则组适用的爬虫；`*` 匹配没有更具体规则组的任何爬虫。 |
| `disallow` | 爬虫不应抓取的路径前缀。 |
| `allow` | 可以抓取的路径前缀，用于覆盖范围更大的 `disallow`。 |
| `sitemap` | Sitemap 的绝对 URL，不属于任何规则组。 |

> **官方文档已说明:**
> Google 不支持 `crawl-delay` 等其他字段。当规则冲突时（包括含通配符的规则），Google 采用**限制最少**的那条规则。
>
> 参考来源: [Google: How Google interprets the robots.txt specification](https://developers.google.com/crawling/docs/robots-txt/robots-txt-spec)

路径中支持 `*`（任意字符序列）和 `$`（URL 结尾）。

## 大小限制与缓存

> **官方文档已说明:**
> Google 对 robots.txt 有 500 KiB 的大小限制，超出部分会被忽略。Google 通常会将 robots.txt 缓存最多 24 小时。如果刷新失败（例如超时或返回 5xx 错误），可能缓存更久。
>
> 参考来源: [Google: How Google interprets the robots.txt specification](https://developers.google.com/crawling/docs/robots-txt/robots-txt-spec)

## 抓取不等于索引

> **官方文档已说明:**
> 如果有其他页面链接到被 robots.txt 屏蔽的页面，该页面仍可能出现在搜索结果中，只是没有描述。要让页面不出现在搜索结果中，应允许抓取并使用 `noindex`。
>
> 参考来源: [Google Search Central: Introduction to robots.txt](https://developers.google.com/search/docs/crawling-indexing/robots/intro)

robots.txt 中的 `noindex` 不受支持；请使用 robots meta 标签或 `X-Robots-Tag` 响应头，具体步骤见 [让页面不出现在 Google 中](https://geo.casa/zh-cn/crawling-indexing/keep-out-of-google/)。

## 百度

> **官方文档已说明:**
> Baiduspider 遵守 robots.txt。规则可以针对 `Baiduspider-image` 等按产品区分的 User-Agent 单独设置，但 `Baiduspider-video` 不支持这些规则。屏蔽 `Baiduspider` 后，网站不会出现在百度搜索结果中，也不会出现在「百度提供的任何其他搜索结果」中。`Baiduspider-cpro` 和 `Baiduspider-ads` 按与客户的协议工作，不遵守 robots.txt。
>
> 参考来源: [Baidu: FAQs of Baiduspider](https://help.baidu.com/question?prod_id=99&class=0&id=3001)

这份说明没有为百度的 AI 产品单列 token，也就没有说明怎样把它们和百度搜索区别对待。相比之下，Google 为 Gemini 单独设了一个 token（[Google-Extended](https://geo.casa/zh-cn/crawling-indexing/google-extended/)）。

## 其他国内搜索引擎

> **官方文档已说明:**
> 360 搜索支持 `user-agent`、`allow`、`disallow`，爬虫 token 为 `360Spider`、`360Spider-Image`、`360Spider-Video`。它还自行扩展了 `Indexpage` 字段，用来标出经常更新的页面。
>
> 参考来源: [360 Search: Robots协议支持](https://www.so.com/help/help_3_2.html)

> **官方文档已说明:**
> 搜狗爬虫支持 robots 协议，但新更新的 robots.txt「可能得过几个星期才能体现出效果」。被禁止的网页将无法在搜狗搜索中检索到。
>
> 参考来源: [Sogou: 站长指南](https://www.sogou.com/docs/help/webmasters.htm)

> **官方文档已说明:**
> 头条搜索的爬虫介绍（2019 年）给出了 `Bytespider` 的 UA 和 IP 段，但没有提到 robots.txt。
>
> 参考来源: [Toutiao Search: 头条搜索spider介绍](https://www.toutiao.com/i6759451726496940557/)

## 示例

```txt
user-agent: *
disallow: /search
allow: /search/about

sitemap: https://example.com/sitemap-index.xml
```

## 另请参阅

- [为 AI 爬虫配置 robots.txt](https://geo.casa/zh-cn/crawling-indexing/robots-txt-ai-crawlers/)：为 AI 搜索爬虫和训练爬虫分别设置规则。

## 参考来源

- [IETF: RFC 9309: Robots Exclusion Protocol](https://www.rfc-editor.org/rfc/rfc9309.html)
- [Google: How Google interprets the robots.txt specification](https://developers.google.com/crawling/docs/robots-txt/robots-txt-spec)
- [Google Search Central: Introduction to robots.txt](https://developers.google.com/search/docs/crawling-indexing/robots/intro)
- [Google Search Central: Block Search indexing with noindex](https://developers.google.com/search/docs/crawling-indexing/block-indexing)
- [Baidu: FAQs of Baiduspider](https://help.baidu.com/question?prod_id=99&class=0&id=3001)
- [Sogou: 站长指南](https://www.sogou.com/docs/help/webmasters.htm)
- [360 Search: Robots协议支持](https://www.so.com/help/help_3_2.html)
- [Toutiao Search: 头条搜索spider介绍](https://www.toutiao.com/i6759451726496940557/)
