---
title: 国际化与 AI 友好 URL
description: 多语言站点的 middleware、locale 前缀与 SemanticGraph 路由策略。
canonical_url: https://next-ai-ready.vercel.app/zh/docs/guides/i18n-ai-urls
url: https://next-ai-ready.vercel.app/zh/docs/guides/i18n-ai-urls
last_updated: 2026-08-01
updated: 2026-08-01
author: next-ai-ready 团队
summary: 多语言站点的 middleware、locale 前缀与 SemanticGraph 路由策略。
topics: [how-to, best-practices]
---

# 国际化与 AI 友好 URL

`next-ai-ready` 按 `content` glob 扫描 MDX，并将文件路径映射为路由。多语言站点请在路由中包含 locale（例如 `/zh/docs/install`）。

## 推荐目录结构

```text
content/
  en/
    docs/
      introduction.mdx
      installation.mdx
      guides/quickstart.mdx
  zh/
    docs/
      introduction.mdx
```

```js
export default defineConfig({
  content: ["content/{en,zh}/**/*.mdx"],
});
```

`en`、`zh` 等已识别的路由前缀会写入页面节点的 `locale` 字段。生成的 `SemanticGraph.routesByLocale` 还会将语言内相对路由映射回页面 id，同时保留扁平 `routes` 以兼容现有消费者。

MCP 页面结果会返回 locale；`list_pages` 与 `search_pages` 暂无 locale 过滤参数，因此多语言客户端目前应使用路由前缀缩小结果范围。

## Middleware

若将 `/docs` 重定向到 `/en/docs`，请在 matcher 中排除 AI 产物路径，避免 agent 被重定向：

```ts
export const config = {
  matcher: ["/((?!_next|_ai-ready|api|.*\\..*).*)"],
};
```

需保持可访问的路径：

- `/_ai-ready/*`
- `*.md`、`*.ai.json`（由 `withAiReady()` rewrite）
- `/llms.txt`、`/openapi.json`、`/tools.json`、`/.well-known/ai-plugin.json`

## llms.txt

可用 config `sections` 在 `llms.txt` 中优先展示某一语言，或为每种语言单独部署。

## 当前限制

自动生成 `Available Languages`、Markdown alternate frontmatter、`hreflang` 响应链接以及 MCP locale 过滤仍在规划中。当前边界见 [Phase 6 设计](https://github.com/mustcanbedo/next-ai-ready/blob/main/docs/phase6-design.md)。
