<!-- Generated from zh/how-to-create/index.html. The canonical document is the HTML page. -->

- [ 首页 ](/zh/) 
/
- 如何创建            
# 如何创建 `llms.txt` 文件

三个模板、一个清单，以及适用于每个常见技术栈的可复制部署说明。

最近更新: 2026年8月12日

本页内容

- [ 1. 规划要包含的内容 ](#plan)
- [ 2. 最简模板 ](#minimal)
- [ 3. 推荐模板 ](#recommended)
- [ 4. 高级模板 ](#advanced)
- [ 5. 验证 ](#validate)
- [ 6. 在你的技术栈上部署 ](#deploy)
- [ 7. 在构建时自动生成 ](#auto)
- [ 检查清单 ](#checklist)            
## 1. 规划要包含的内容

在写任何内容之前，先列出这些 **5 到 20 页** ，即 LLM 回答与你的项目有关的问题时可能需要的网站页面。应将其视为精选阅读列表，而非站点地图。

实用的初始分类：

- **产品**，概览、用例、定价。 
- **文档**、入门指南、API 参考和关键指南。 
- **集成**、合作伙伴和 SDK，每项一行。 
- **参考**、更新日志、状态页、安全政策。 
- **可选**、品牌素材、新闻资料、归档。   
如果某个页面无法帮助 LLM
回答真实的用户问题，就不要将其列入。最大的错误是把所有内容都包括进来，这会稀释信号。

## 2. 最小模板

H1 标题是唯一必需的元素。下面的模板添加了摘要和链接，使文件更有用。
llms.txt, minimal    复制     

```
# {Site name}

> {One-sentence description of what your site is about.}

## Pages

- [{Page title}]({absolute URL}): {short note}

```

## 3. 推荐模板

对大多数网站而言，此模板是合适的起点：块引用摘要、一段背景说明，以及三到四个章节。
llms.txt, recommended    复制     

```
# {Site name}

> {One- or two-sentence overview. Factual, no marketing claims.}

{Optional 1–3 sentences of context: what this site covers, who it's for, and how the file below is curated.}

## Product

- [Product overview]({URL}): high-level capabilities.
- [Pricing]({URL}): plans and limits.

## Documentation

- [Getting started]({URL}): install, first call, hello world.
- [API reference]({URL}): full endpoint catalog.
- [Guides]({URL}): tutorials and how-tos.

## Optional

- [Changelog]({URL}): version history.
- [Brand assets]({URL}): logos and color palette.

```

## 4. 高级模板

较大型的 SaaS 或开发者平台通常需要更深层的结构，并设置专门的 `Optional` 分节。以此为起点，并进行严格精简。
llms.txt, advanced    复制     

```
# Acme

> Acme is a hosted analytics platform for product teams. The pages below cover product, pricing, the API, and integration guides.

The map here is curated for assistants, it is not exhaustive. Use it to answer questions about product capabilities, pricing tiers, integrations, SDKs, and migration from other tools. For the full corpus, see /llms-full.txt.

## Product

- [Product overview](https://acme.example/product): high-level capabilities.
- [Use cases](https://acme.example/use-cases): scenarios for product, marketing, and support teams.
- [Changelog](https://acme.example/changelog): monthly product updates.

## Pricing

- [Pricing tiers](https://acme.example/pricing): plans, limits, overage rules.
- [Billing FAQ](https://acme.example/billing-faq): invoices, taxes, refunds.

## Developers

- [REST API reference](https://docs.acme.example/api): full endpoint catalog.
- [Webhooks](https://docs.acme.example/webhooks): events, signatures, retries.
- [SDK, JavaScript](https://docs.acme.example/sdk/js): install, init, track events.
- [SDK, Python](https://docs.acme.example/sdk/python): install, init, track events.

## Integrations

- [Segment](https://docs.acme.example/integrations/segment): two-way sync.
- [Snowflake](https://docs.acme.example/integrations/snowflake): nightly export.
- [HubSpot](https://docs.acme.example/integrations/hubspot): contacts and events.

## Optional

- [Brand assets](https://acme.example/brand): logos, color palette.
- [Press releases](https://acme.example/press): historical announcements.
- [Status page](https://status.acme.example): real-time service health.

```

示例

使用生成器

不想从模板开始？使用
生成器 ：填写表单并下载一个干净文件。

## 5. 验证

将您的文件粘贴到 [验证器](/zh/validator/) ，确认它符合规范。它可以发现的常见问题包括：缺少
H1、链接语法格式错误（`- [name](url)`）、相对 URL、分节外内容、意外出现的第二个
H1、过大的文件。

## 6. 在你的技术栈上部署

### Cloudflare Pages
Cloudflare Pages    复制     

```
# Cloudflare Pages
# Place llms.txt in the public/ root of your project. It will be served at /llms.txt.

# Verify after deploy:
curl -I https://your-domain.com/llms.txt

```

→ [完整的 Cloudflare Pages 指南](/zh/llms-txt-cloudflare/)

### Vercel

放置 `llms.txt` 放入项目的 `public/` 目录。Vercel 会按原样通过以下路径提供它：
`/llms.txt`.

→ [完整 Vercel 指南](/zh/llms-txt-vercel/)

### Netlify

方法相同：将文件放入静态目录（`public/`
对于 Next.js 或 Astro， `static/` ；SvelteKit 和 Hugo 则使用 static/）。Netlify 会将其提供于
`/llms.txt`.

→ [Netlify 完整指南](/zh/llms-txt-netlify/)

### Next.js
Next.js    复制     

```
// Next.js (App Router), public/llms.txt is served as-is.
// 1. Place the file at: public/llms.txt
// 2. No code change needed, it's served at https://yoursite.com/llms.txt

// If you prefer to generate it dynamically:
// app/llms.txt/route.ts
import { NextResponse } from 'next/server';

export async function GET() {
const body = `# Acme

> One-line summary.

## Docs

- [Getting started](https://acme.example/docs/getting-started)
`;

return new NextResponse(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}

```

→ [Next.js 完整指南](/zh/llms-txt-nextjs/)

### Astro
Astro    复制     

```
// Astro, public/llms.txt is served as-is.
// Drop the file at: public/llms.txt
// Astro will copy it to dist/llms.txt during `astro build`.

// To generate it from your content collections, create:
// src/pages/llms.txt.ts
import type { APIRoute } from 'astro';
import { getCollection } from 'astro:content';

export const GET: APIRoute = async () => {
const docs = await getCollection('docs');
const body = [
'# Acme',
'',
'> Hosted analytics for product teams.',
'',
'## Documentation',
'',
...docs.map((d) => `- [${d.data.title}](https://acme.example/${d.slug}/): ${d.data.summary}`),
].join('\\n');

return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
};

```

→ [完整 Astro 指南](/zh/llms-txt-astro/)

### SvelteKit
SvelteKit    复制     

```
// SvelteKit, static/llms.txt is served as-is.
// Drop the file at: static/llms.txt
// SvelteKit copies it to build/llms.txt during build.

// To generate it dynamically, create:
// src/routes/llms.txt/+server.ts
import type { RequestHandler } from './$types';

export const GET: RequestHandler = () => {
const body = `# Acme

> One-line summary.

## Docs

- [Getting started](https://acme.example/docs/getting-started)
`;

return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};

```

→ [完整的 SvelteKit 指南](/zh/llms-txt-sveltekit/)

### Hugo
Hugo    复制     

```
# Hugo, place llms.txt in the static/ folder.
# It will be copied to public/llms.txt during hugo build.

# To generate it from content, create a custom output format.
# config.toml:
[outputs]
home = ["HTML", "RSS", "LLMSTXT"]

[outputFormats.LLMSTXT]
name = "LLMSTXT"
mediaType = "text/plain"
baseName = "llms"
isPlainText = true
notAlternative = true

# layouts/index.llmstxt:
# {{ "# " }}{{ .Site.Title }}
#
# > {{ .Site.Params.description }}
#
# ## Pages
#
# {{ range .Site.RegularPages }}- [{{ .Title }}]({{ .Permalink }}): {{ .Params.summary }}
# {{ end }}

```

→ [完整 Hugo 指南](/zh/llms-txt-hugo/)

### WordPress
WordPress    复制     

```
# WordPress, three options
#
# 1. Easiest: upload llms.txt to your hosting (FTP/SFTP) at the web root.
#    Verify: https://yoursite.com/llms.txt
#
# 2. Plugin: any "static file uploader" plugin works. Place file at root.
#
# 3. Programmatic: add a small handler to your theme's functions.php
#    that intercepts the request and returns the file contents.
add_action('init', function () {
if (\$_SERVER['REQUEST_URI'] === '/llms.txt') {
header('Content-Type: text/plain; charset=utf-8');
echo file_get_contents(get_template_directory() . '/llms.txt');
exit;
}
});

```

→ [完整 WordPress 指南](/zh/llms-txt-wordpress/)

### Express
Express    复制     

```
// Express, serve llms.txt as a static file or dynamic route.

// Option 1: static file in public/
app.use(express.static('public')); // serves public/llms.txt at /llms.txt

// Option 2: dynamic route
app.get('/llms.txt', (req, res) => {
res.type('text/plain');
res.send(`# Acme

> One-line summary.

## Docs

- [Getting started](https://acme.example/docs/getting-started)
`);
});

```

→ [完整 Express 指南](/zh/llms-txt-express/)

### Laravel
Laravel    复制     

```
One-line summary.

## Docs

- [Getting started](https://acme.example/docs/getting-started)
EOT;

return response($content, 200)
->header('Content-Type', 'text/plain; charset=utf-8');
});

// Or use a controller:
// php artisan make:controller LlmsTxtController
// Then: Route::get('/llms.txt', [LlmsTxtController::class, 'show']);

```

→ [完整 Laravel 指南](/zh/llms-txt-laravel/)

### CMS（Contentful、Sanity、Strapi、Prismic）
CMS build script    复制     

```
# CMS-driven llms.txt (Contentful, Sanity, Strapi, Prismic…)
#
# Pattern: fetch curated entries at build time, write llms.txt.
#
# Node.js example (runs in CI or as a build script):

import { createClient } from 'contentful';
import fs from 'fs/promises';

const client = createClient({
space: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
});

const entries = await client.getEntries({ content_type: 'doc', 'fields.featured': true });

const lines = [
'# Acme',
'',
'> Hosted analytics for product teams.',
'',
'## Documentation',
'',
...entries.items.map(
(e) => `- [${e.fields.title}](https://acme.example/${e.fields.slug}/): ${e.fields.summary}`
),
];

await fs.writeFile('public/llms.txt', lines.join('\n'));
console.log(`Wrote ${entries.items.length} entries to llms.txt`);

```

→ [完整 CMS 指南](/zh/llms-txt-cms/)

### 更多平台指南

其他常见技术栈和建站工具的分步指南：

- [Angular](/zh/llms-txt-angular/), [Vue（Vite）](/zh/llms-txt-vue/), [Nuxt](/zh/llms-txt-nuxt/), [Remix](/zh/llms-txt-remix/), [Gatsby](/zh/llms-txt-gatsby/) 
- [Docusaurus](/zh/llms-txt-docusaurus/), [MkDocs](/zh/llms-txt-mkdocs/), [Jekyll](/zh/llms-txt-jekyll/), [Eleventy](/zh/llms-txt-eleventy/), [GitHub Pages](/zh/llms-txt-github-pages/) 
- [Ruby on Rails](/zh/llms-txt-rails/), [Django](/zh/llms-txt-django/), [Laravel](/zh/llms-txt-laravel/), [Express](/zh/llms-txt-express/) 
- 无代码： [Framer](/zh/llms-txt-framer/), [Webflow](/zh/llms-txt-webflow/), [Wix](/zh/llms-txt-wix/), [Squarespace](/zh/llms-txt-squarespace/), [Ghost](/zh/llms-txt-ghost/), [Shopify](/zh/llms-txt-shopify/)   
### 其他技术栈

对于静态 `nginx`，把文件复制到你的 web 根目录。规则是通用的：在规范路径 `/llms.txt`
搭配 `Content-Type: text/plain; charset=utf-8`.

## 7. 在构建时自动生成

对于小型站点，手动维护文件没问题，但很快就会失效。两种常见 模式：

- **构建脚本**，遍历您的内容集合（Markdown、MDX、CMS），然后 写入 `llms.txt` 在 `dist/`。请参阅上文的 Astro 和 CMS 示例。 
- **服务器路由**，按需从数据库或 CMS 渲染文件。上文提供了 Next.js、
SvelteKit、Express 和 Laravel 示例。   
无论选择哪一种，都应在 CI 中运行 [验证器](/zh/validator/) 纳入 CI：它会发现悄然损坏的文件（例如内容迁移后出现的空分节）。

## 发布前检查清单

- 文件提供于 `/llms.txt` 与 `200 OK`. 
- `Content-Type: text/plain; charset=utf-8`. 
- 恰好一个 H1。 
- 使用浅显语言编写的引用块摘要，不含营销套话。 
- 所有 URL 均为 **绝对** (`https://...`). 
- 每个部分至少包含一项。 
- 未列出任何私有或需认证的 URL。 
- 验证器未返回错误。 
- 如果你有要公开的语料，也请发布 [`/llms-full.txt`](/zh/llms-full-txt/). 
- `robots.txt` 仍允许抓取该文件（不要 `Disallow: /llms.txt`).   
## 下一步

- [最佳实践](/zh/best-practices/)，哪些做法应继续，哪些应避免。 
- [llms.txt 与 SEO](/zh/llms-txt-seo/)，AI 引用、GEO 信号、排名。 
- [llms-full.txt](/zh/llms-full-txt/)，公开你的完整内容语料库。 
- [真实案例](/zh/examples/)，借鉴有效做法。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).        
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ Mintlify，使用 llms.txt 简化文档 ](https://www.mintlify.com/blog/simplifying-docs-with-llms-txt)
