robots.txt
简明回答
robots.txt 告诉爬虫可以抓取哪些 URL 路径,已标准化为 RFC 9309。它只控制抓取,不控制索引。被禁止抓取的 URL 如果有其他页面链接,仍可能在没有内容的情况下被编入索引。
- 放在每个主机名和协议的根目录
/robots.txt(https://example.com/robots.txt不覆盖https://shop.example.com/)。 - 纯文本,UTF-8 编码。每组规则以一行或多行
user-agent开头,后跟allow/disallow规则。
支持的字段(Google)
Section titled “支持的字段(Google)”| 字段 | 作用 |
|---|---|
user-agent | 规则组适用的爬虫;* 匹配没有更具体规则组的任何爬虫。 |
disallow | 爬虫不应抓取的路径前缀。 |
allow | 可以抓取的路径前缀,用于覆盖范围更大的 disallow。 |
sitemap | Sitemap 的绝对 URL,不属于任何规则组。 |
路径中支持 *(任意字符序列)和 $(URL 结尾)。
大小限制与缓存
Section titled “大小限制与缓存”抓取不等于索引
Section titled “抓取不等于索引”robots.txt 中的 noindex 不受支持;请使用 robots meta 标签或 X-Robots-Tag 响应头,具体步骤见 让页面不出现在 Google 中。
这份说明没有为百度的 AI 产品单列 token,也就没有说明怎样把它们和百度搜索区别对待。相比之下,Google 为 Gemini 单独设了一个 token(Google-Extended)。
其他国内搜索引擎
Section titled “其他国内搜索引擎”user-agent: *disallow: /searchallow: /search/about
sitemap: https://example.com/sitemap-index.xml- 为 AI 爬虫配置 robots.txt:为 AI 搜索爬虫和训练爬虫分别设置规则。