> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/docs-site/site-redirects.md).

# 站点重定向

{% hint style="info" %}
此功能适用于 [高级和终极站点方案](https://www.gitbook.com/pricing).
{% endhint %}

<figure><img src="/files/4fcef0be70b09a308abd746b90125f21298309f8" alt="A GitBook screenshot showing site redirects"><figcaption><p>当迁移文档或重组内容时，站点重定向很有用，可以避免损坏链接，因为损坏链接会影响 SEO。</p></figcaption></figure>

当你把文档从一个提供商迁移到另一个提供商时，重定向很常用——比如你刚把文档迁移到 GitBook 时。损坏链接会影响 SEO，因此我们建议在需要的地方设置重定向。

除了 [GitBook 自动创建的重定向](#about-automatic-redirects)之外，你还可以为站点域名中的任意路径创建重定向。

重定向可以创建为 **生效** 或 **草稿**。草稿重定向允许你在发布前准备并审查重定向规则。草稿在启用之前不会影响你的线上站点。

## 管理站点中的重定向

要开始操作，请打开站点侧边栏中的 **设置**，在……下 **常规** ，然后点击 **重定向**.

### 创建重定向

点击 **添加重定向** 并选择 **手动** 选项。

填写 **源路径** ——你想要重定向的 URL slug——以及 **目标** 内容，也就是你希望访客被送往的页面。你可以选择站点中的任意章节、变体或页面。

点击 **启用重定向** 以立即启用该重定向。

如果你想创建该重定向，但暂时不让它上线，请点击 **另存为草稿** 。草稿重定向会出现在 **草稿** 选项卡中，并可稍后启用。

你也可以创建 **通配符重定向** ，方法是在源路径末尾添加 \*，例如：

* /docs/\* 用于匹配 /docs/ 下的所有内容
* /changelog\* 用于匹配以 /changelog 开头的路径

当你的源路径包含通配符（\*）时，你可以启用 **用匹配到的文本替换通配符**.

* **开启：** 被 \* 匹配到的部分会附加到目标路径后。
  * 示例：源 /docs/\* → 目标 /help\n/docs/install 会重定向到 /help/install
* **关闭：** 所有匹配的 URL 都会重定向到同一个固定目标。
  * 示例：源 /docs/\* → 目标 /help\n/docs/install 会重定向到 /help

如果你想为同一个页面添加另一个重定向，请切换 **添加另一个重定向** ，然后再点击 **启用重定向** 或 **另存为草稿**.

添加重定向后，弹窗会保持打开状态，目标内容会保留为你上一次的选择，这样你就可以快速添加另一个源路径。

{% hint style="warning" %}
**注意：** GitBook 会不区分大小写地解析已发布的 URL，因此两个仅在大小写上不同的重定向会被视为同一路径。如果你是从使用大小写敏感 URL 的平台迁移过来，可能需要在导入前合并重定向。
{% endhint %}

### 编辑重定向

要编辑重定向，请点击列表中它旁边的 **编辑** 图标。更新重定向后，点击 **启用重定向** 以发布你的更改。

如果该重定向当前是 **草稿**，你也可以在编辑弹窗中直接点击 **启用重定向**.

### 启用草稿重定向

草稿重定向会出现在重定向表格的 **草稿** 选项卡中。

你可以通过两种方式发布草稿重定向：

• 打开该重定向并点击 **启用重定向** 在编辑弹窗中。\n• 使用表格中的 **切换开关** 直接启用该重定向。

启用后，该重定向会移到 **生效** 选项卡，并立即开始为访问者路由。

### 从 CSV 导入重定向

点击 **添加重定向** 并选择 **上传 CSV**.

上传一个包含以下列的 CSV： `源`, `目标`，以及可选的 `意图`.

* `源` 是你想要重定向的路径，例如 /docs/site-redirects
* `目标` 可以是：
  * 某个特定页面，使用页面的管理后台 URL，如下方截图所示
  * 外部 URL
  * 空值，具体取决于 intent
* `意图` 可以是：
  * live、留空，或完全省略，用于创建、更新或移除生效重定向
  * draft，用于创建、更新或移除草稿重定向
  * publish，用于将现有草稿重定向发布为生效， `目标` 必须为空。

<div data-with-frame="true"><figure><img src="/files/c498fb0b8439c14fe765ac5529e1bca840ce63b8" alt=""><figcaption><p>你可以在此菜单中找到某个页面的 GitBook 管理后台 URL</p></figcaption></figure></div>

每次导入最多支持 500 行。

如果你的 CSV 包含重复的 source 值，则只处理第一行。导入会按 upsert 方式运行：具有相同 source 的现有重定向会被更新，不存在的 source 会创建新的重定向。

如果有任何行失败，右下角的提示气泡中会提供一个错误 CSV。它包含 source、destination，以及每个错误的简短说明，方便你修复后，删除 errors 列并重新导入。

#### CSV 示例

| 源                    | 目标                         | 意图 | 结果            |
| -------------------- | -------------------------- | -- | ------------- |
| /docs/site-redirects | <https://example.com/page> | 空白 | 创建或更新生效重定向    |
| /docs/site-redirects | <https://example.com/page> | 生效 | 创建或更新生效重定向    |
| /docs/site-redirects | <https://example.com/page> | 草稿 | 创建或更新草稿重定向    |
| /docs/site-redirects | 空                          | 空白 | 移除生效重定向       |
| /docs/site-redirects | 空                          | 生效 | 移除生效重定向       |
| /docs/site-redirects | 空                          | 草稿 | 移除草稿重定向       |
| /docs/site-redirects | 空                          | 发布 | 将现有草稿重定向发布为生效 |

## 关于自动重定向

每当页面被移动或重命名时，它们的规范 URL 也会随之改变。为了保持内容可访问，GitBook 会自动创建一个 [HTTP 307](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307) 从旧 URL 到新 URL 的重定向。

每次加载 URL 时，GitBook 都会按以下步骤解析它：

1. 通过跟随任何自动创建的重定向，将站点内容解析到其规范 URL。
2. 如果无法解析该 URL，则会将其与 [章节级重定向](/docs/documentation/zh/getting-started/git-sync/content-configuration.md#redirects)进行检查，这些重定向定义在你仓库的 `.gitbook.yaml` 文件。
3. 最后，会将该 URL 与站点级重定向进行检查，这些重定向通过 [上面的流程](#creating-redirects).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/docs-site/site-redirects.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
