---
title: 国际化与 AI 友好 URL
description: 多语言站点的 middleware、locale 前缀与 SemanticGraph 路由策略。
canonical_url: https://nextaiready.com/zh/docs/guides/i18n-ai-urls
url: https://nextaiready.com/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。调用 `search_pages` 时传入 `locale` 可限制检索语言；`list_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 `search_pages` 的 locale 过滤已经可用。当前边界见 [Phase 6 设计](https://github.com/mustcanbedo/next-ai-ready/blob/main/docs/phase6-design.md)。
