TL;DR
Cloudflare 的 bot_management 配置中,ai_bots_protection: block 会把 GPTBot、ClaudeBot、PerplexityBot 等 AI 爬虫全部 403。把该字段改为 allow(API 会规范化为 disabled)并关闭 managed robots.txt 即可放行。本文记录完整诊断与操作过程。
一、现象
2026-08-02,本站上线后做爬虫友好性测试,发现:
| User-Agent | 结果 |
|---|---|
| 普通浏览器 | 200 |
| Googlebot | 200 |
| GPTBot / ClaudeBot / PerplexityBot / Bytespider | 403 "Your request was blocked" |
同时 robots.txt 被 Cloudflare 前置注入了一段 Content-Signal: search=yes, ai-train=no, use=reference。
二、定位
用账户级 API 读取 zone 的 bot 配置:
GET /zones/{zone_id}/bot_management
关键字段:
{
"ai_bots_protection": "block",
"fight_mode": false,
"is_robots_txt_managed": true,
"cf_robots_variant": "off"
}
ai_bots_protection: block 就是拦截 AI 爬虫的开关;is_robots_txt_managed: true 则是 robots.txt 注入的来源。
三、修复
PUT /zones/{zone_id}/bot_management
请求体(只列改动项):
{
"ai_bots_protection": "allow",
"is_robots_txt_managed": false
}
实测 API 会把 allow 规范化为 disabled 返回,语义相同(不启用拦截)。
四、验证
配置生效有约 1–2 分钟传播延迟。之后用各 AI 爬虫 UA 重新请求:
curl -A "GPTBot/1.0" https://example.com/llms.txt
curl -A "ClaudeBot/1.0" https://example.com/llms.txt
curl -A "PerplexityBot/1.0" https://example.com/llms.txt
全部返回 200 即成功。robots.txt 恢复为站点自有的放行版本。
五、注意事项
- 需要 Zone Settings: Edit 与 Bot Management 相关权限;只读 token 会得到 9109 / 10000 错误。
- 若只想保留搜索抓取、拒绝训练,可改为启用 managed robots.txt 并配置
cf_robots_variant,而不是全关。 - 修改后建议把 UA 测试固化为 CI 或定时脚本,防止未来被重新打开。
结论
AI 爬虫放行是"agent 优先"站点的基础设施操作,接口明确、验证简单,值得沉淀为可复用脚本。