给 llms.txt 做一次 robots 体检:38 站里 4 站被判死
导语:llms.txt 不控制访问,robots.txt 才控制。我们对 38 个站做了 robots 组级判定,4 站的 /llms.txt 在 AI 爬虫身份下直接被判 DISALLOW,另有一站返回 200 却给出 285KB 首页 HTML。
背景:文件写对了,门却锁着
做 AI 可见度的团队这两年在 llms.txt 上投入最多的动作是"写文件":根目录放一个 llms.txt,再补一个 llms-full.txt,标题、摘要、链接分节排好,收工。
但真实链路是:AI 爬虫先看 robots.txt,被允许后才去取 llms.txt。只要 robots 里有一个 Disallow: / 落在该 UA 组下,前面所有写作工作对这台爬虫等于零——而且没有任何报错。站长后台看不到 403,站点日志里只有一条不那么显眼的抓取记录,人也不会收到通知。
所以这次我们不做"怎么写出漂亮的 llms.txt",而是反过来:把 28 个可达站的 robots.txt 按 UA 组逐条匹配一遍,看谁的 llms.txt 实际上取不到。
选题的冲突类型学参考了 aiwebpageseo(2026-09-28)关于 robots 规则误拦 llms.txt 的归纳,包含 Disallow: /*.txt$ 这类通配写法、Allow: /llms.txt 与 Disallow: / 同组打架、以及 CDN/防火墙层拦截;具体数据全部来自本次本机实测,不是转述。
落地清单
1. 先摆正确姿势:三份真实 robots.txt
svelte.dev(最省事,24 字节)
User-agent: * Disallow:
全站放行,不区分 UA。配合它 1,676 字节的 llms.txt,是成本最低的一组。
supabase.com(121 字节,多了 Content-Signal)
User-agent: * Allow: / Sitemap: https://supabase.com/sitemap.xml Content-Signal: ai-train=yes, search=yes, ai-input=yes
Content-Signal 是这两年冒出来的新兴字段,用一行把"训练 / 检索 / 输入"三类用途分开表态,比一刀切 Disallow 精细,也比在 robots 里堆十几个 UA 组好维护。注意它目前没有进入 robots.txt 的正式规范,主流爬虫是否遵守并不一致,按"表达意图"用,不要当强制开关。
www.figma.com(反例,实测被判死的写法)
User-Agent: GPTBot Allow: /pricing/$ Allow: /pricing-faq/$ Disallow: / User-Agent: cohere-ai
逻辑上这是很清楚的策略:只让 AI 看价格页,正文不给。问题在于站点同时存在 llms.txt 这条路径——用 GPTBot 身份实测 /llms.txt 返回 404,判定为 DISALLOW(最长匹配 Disallow:/)。也就是说,索引文件写在被封锁的地基上。同类实测还有 linkedin.com(robots 78 组)、amazon.com(101 组)、cnn.com,四站的 /llms.txt 在 GPTBot 身份下全部 DISALLOW。
如果要保留"正文不给、索引给"的策略,正确写法是给该组单独开一条精确 Allow,且优先级要压过 Disallow: /:
User-Agent: GPTBot Allow: /llms.txt$ Allow: /llms-full.txt$ Allow: /pricing/$ Disallow: /
2. 上线前跑一遍组级判定器
光看 robots 文本没用,人眼容易漏掉"这个组到底匹配不匹配我的 UA""同长度 Allow 和 Disallow 谁赢"。下面这段是本机实测实际使用的判定器,独立可跑,无第三方依赖,直接把它塞进 CI 或发布前脚本:
# robots_probe.py —— robots 组级判定 + llms.txt 可达性交叉核验
import re, requests
BROWSER = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/131.0 Safari/537.36"
def parse_groups(txt):
groups, cur, last_ua = [], None, False
for raw in txt.splitlines():
line = raw.split("#", 1)[0].strip()
if not line or ":" not in line:
continue
k, v = line.split(":", 1)
k, v = k.strip().lower(), v.strip()
if k == "user-agent":
if cur is None or not last_ua:
cur = {"uas": [], "rules": []}
groups.append(cur)
cur["uas"].append(v)
last_ua = True
elif k in ("allow", "disallow"):
if cur is not None:
cur["rules"].append((k, v))
last_ua = False
return [g for g in groups if g["uas"]]
def pat_match(pat, path):
if pat == "":
return False
if pat == "/":
return True
anchored = pat.endswith("$")
p = pat[:-1] if anchored else pat
rx = "^" + "".join(".*" if c == "*" else re.escape(c) for c in p) + ("$" if anchored else "")
return re.match(rx, path) is not None
def pick_rules(groups, ua):
ua_l = ua.lower()
hit = [g for g in groups for t in g["uas"] if t.lower() != "*" and t.lower() in ua_l]
if hit:
return hit # 具名组优先于通配组
return [g for g in groups if any(t.strip() == "*" for t in g["uas"])]
def judge(groups, ua, path):
rules = pick_rules(groups, ua)
if not rules:
return "ALLOW", "无匹配组"
cand = [(len(pat), typ, pat) for g in rules for typ, pat in g["rules"] if pat_match(pat, path)]
if not cand:
return "ALLOW", "无规则命中"
mx = max(c[0] for c in cand)
tops = [c for c in cand if c[0] == mx]
if any(c[1] == "allow" for c in tops):
return "ALLOW", "最长匹配 Allow:%s" % tops[0][2] # 同长度 Allow 胜
return "DISALLOW", "最长匹配 Disallow:%s" % tops[0][2]
def check(host, ua="GPTBot"):
g = parse_groups(requests.get("https://%s/robots.txt" % host,
headers={"User-Agent": BROWSER}, timeout=20).text)
verdict, why = judge(g, ua, "/llms.txt")
# 再用该 UA 真实取一次,和判定结论对照
r = requests.get("https://%s/llms.txt" % host,
headers={"User-Agent": "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)"},
timeout=25)
return verdict, why, r.status_code, len(r.content), r.headers.get("Content-Type", "")
if __name__ == "__main__":
print(check("www.figma.com")) # ('DISALLOW', '最长匹配 Disallow:/', 404, 9586, 'text/html...')
print(check("svelte.dev")) # ('ALLOW', '无规则命中', 200, 1676, 'text/plain; charset=utf-8')三个容易写错的地方,都在代码里显式处理了:具名组优先于 * 组(不是合并)、最长匹配优先(/llms.txt$ 长过 /)、同长度 Allow 胜(这是主流爬虫的通行实现,但不是所有文档都写清楚)。
3. llms.txt 原文怎么分块
svelte.dev 的 1,676 字节全文是"小文件 + 三档体积"的标准形态,可以直接对照着改:
# Svelte Documentation for LLMs > Svelte is a UI framework that uses a compiler to let you write breathtakingly concise components that do minimal work in the browser, using languages you already know — HTML, CSS and JavaScript. ## Documentation Sets - [Abridged documentation](https://svelte.dev/llms-medium.txt): A shorter version of the Svelte and SvelteKit documentation, with examples and non-essential content removed - [Compressed documentation](https://svelte.dev/llms-small.txt): A minimal version of the Svelte and SvelteKit documentation, with many examples and non-essential content removed - [Complete documentation](https://svelte.dev/llms-full.txt): The complete Svelte and SvelteKit documentation including all examples and additional content ## Individual Package Documentation - [Svelte documentation](https://svelte.dev/docs/svelte/llms.txt): This is the developer documentation for Svelte. - [SvelteKit documentation](https://svelte.dev/docs/kit/llms.txt): This is the developer documentation for SvelteKit. - [Svelte CLI documentation](https://svelte.dev/docs/cli/llms.txt): This is the developer documentation for Svelte CLI. - [Svelte AI documentation](https://svelte.dev/docs/ai/llms.txt): This is the developer documentation for Svelte AI. ## Notes - The abridged and compressed documentation excludes legacy compatibility notes, detailed examples, and supplementary information - The complete documentation includes all content from the official documentation - Package-specific documentation files contain only the content relevant to that package
要点有三:索引文件只做索引(不在 llms.txt 里塞正文);按体积给档位(small / medium / full,让代理自己按上下文预算挑,而不是一次性吃下全量);子集单独出文件(每个子包一个 llms.txt,主文件只负责导航)。
docs.github.com 走的是另一条路:它返回的 Content-Type 是 text/markdown,正文里不列文档链接,而是列 API——"要取内容请走这些接口"。对 API 型文档站,这比生成几十万链接的索引更实用:
## How to use To retrieve full article content, page lists, or search results programmatically, please use the APIs below... * [Article API](https://docs.github.com/api/article): Returns the full rendered content and context of any docs page as JSON. * [Article Body API](https://docs.github.com/api/article/body): Returns the full rendered content of any docs page as markdown. * [Search API](https://docs.github.com/api/search/v1): Search across all docs content.
4. 体积与 Content-Type
本次实测 17 个有效文件的体积分布:< 5KB 3 个、5–50KB 13 个、≥ 50KB 1 个(stripe.com 69,815 字节,31 个二级标题、307 条链接)。最大和最小的差距 41 倍。实测中位数落在 16KB 上下,这个量级对代理一次读全毫无压力;超过 50KB 就该考虑拆档了。
Content-Type 也不统一:14 个站返回 text/plain,docs.github.com 与 sanity.io 返回 text/markdown。两者都能被解析,但如果站点同时做了 v2 的内容协商(<link rel="alternate" type="text/markdown">),建议保持一致,别让同一份内容在两种入口下给出不同 MIME。
结果:38 站横截面
实测时间 2026-11-23,本机 Windows 10 + Python 3 + requests,单请求超时 20–25 秒;取 GPTBot 身份请求 /llms.txt(UA 串 Mozilla/5.0 (compatible; GPTBot/1.2; ...))。
| 分类 | 站数 | 说明 |
|---|---|---|
| 取样总量 | 38 | 以文档站、开发者工具、SaaS 为主 |
| 网络不可达 | 10 | medium / reddit / nytimes / wsj / guardian / HN / quora / etsy / bbc / wikipedia 连接超时,不计入结论 |
| 有效 llms.txt(200 + 非 HTML) | 17 | 均自带 H1,均无 BOM |
| 200 但返回 HTML | 1 | canva.com:285,071 字节、text/html、0 个标题,是首页兜底 |
| 404 | 6 | 其中 4 站 404 仍吐出 8–36 万字节 HTML(linkedin 364,780 / airtable 310,031 / tailwindcss 133,679 / anthropic 82,179) |
| 403 / 451 / 503 | 4 | stackoverflow 403、wordpress 403、cnn 451、amazon 503 |
| robots 判定 DISALLOW | 4 | linkedin / amazon / cnn / figma,全部源自具名 AI UA 组的 Disallow: / |
*.txt 通配误伤 | 0 | 28 个可达站中未命中一例 |
三个必须说清的发现:
一、*.txt 通配冲突在这个样本里是 0,真正的问题是"具名组整站封"。 网上讨论最多的 Disallow: /*.txt$ 写法,在 28 个可达站里一例都没有;反而有 4 站用 User-Agent: GPTBot 之类的具名组直接 Disallow: /,把 llms.txt 一起带走。结论是:先查自己有没有具名 AI 组,再查通配,顺序反了会白忙。
二、200 不代表有文件,404 不代表没有页面。 canva.com 的 /llms.txt 返回 200 + text/html + 285KB 首页;linkedin 返回 404 但同时吐了 364,780 字节 HTML。这两类都必须靠"看 Content-Type + 看有没有 H1"来判,只看状态码会写下错结论。同理,stackoverflow 的 robots.txt 本身就是 403(Cloudflare 挑战页 Just a moment...)——robots 取不到时,判定器只能兜底 ALLOW,这是所有自动化检测的天然盲区。
三、头部站点的 BOM 问题在本样本为零。 17 个有效文件全部以 # 开头、无 UTF-8 BOM。这说明大厂构建流水线对编码处理得干净;但如果你的生成脚本是 Windows 上写文件,仍然建议用 encoding="utf-8-sig" 读取、写出时显式 utf-8,否则首行 H1 会被行首锚定正则漏计。
定性观察(无量化):把 figma 那组 Allow: /pricing/$ 的写法拆开看,它的意图是"让 AI 读价格、不读正文"。这类站真正该做的是给 llms.txt 与 llms-full.txt 各开一条精确 Allow,再用 Content-Signal 表达训练取舍——不然规则只完成了一半,白名单放出去的门连索引文件都进不来。
复盘
三条可直接抄的配置
robots.txt里若存在任何具名 AI UA 组,必须先给/llms.txt$和/llms-full.txt$开精确 Allow,且确认它比Disallow: /更长(长度决定优先级)。llms.txt 只做索引,正文拆到
llms-small/medium/full三档,主文件控制在 5–20KB,超过 50KB 就拆。发布流水线里加一步组级判定:
judge(groups, "GPTBot", "/llms.txt")必须返回 ALLOW,再用该 UA 真取一次 200 + 非 HTML,两个条件都过才算上线。
两条踩坑提醒
别只看状态码。200 可能是 SPA 兜底首页,404 也可能带着 30 万字节正文。判定必须同时看 Content-Type 与是否存在
#标题行。robots.txt 本身可能取不到。本次 stackoverflow / wordpress.com 的 robots 分别是 403(Cloudflare 挑战页),此时任何"判定为 ALLOW"都是兜底假象,报告里必须明确标注"robots 不可读,结论未验证",不能写成合规。
标注
llms.txt 规范状态:由 Answer.AI 的 Jeremy Howard 于 2024-09 提出的作者主张提案,未被 OpenAI / Anthropic / Google 等 LLM 厂商确认为官方标准;各站实现差异大,本文所有结论仅描述 2026-11-23 这一时点的实测状态。
观察到的形态:v1 纯索引(svelte.dev、supabase.com 等)与 v2 内容协商(docs.github.com、sanity.io 返回
text/markdown)并存。数据来源:本机实测,2026-11-23;冲突类型学参考 aiwebpageseo《Fixing robots.txt Rules That Block AI Crawlers From Your llms.txt》(2026-09-28)。
口径:取样非随机(文档站 / 开发者工具 / SaaS 为主),28 站可达样本不足以代表全网;"4 站被判死"指该 28 站中的 4 站。
标签:llms.txt、AI可见度、AIWO、结构化暴露、开发者工具