# HTTP 301

**HTTP 301** 是状态码“永久移动”（Moved Permanently），即超文本传输协议中的一种重定向响应，它告知客户端：所请求的资源已被赋予一个新的永久 URI，今后对该资源的引用都应使用新地址。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 浏览器收到后会自动请求响应 `Location` 头中给出的 URL；搜索引擎则把这一重定向视为信号，认为目标 URL 应当在其索引中取代原 URL。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)</sup>

| 要点 | 详情 |
|---|---|
| 含义 | 目标资源已被赋予新的永久 URI；今后对该资源的任何引用都应使用所给出的 URI 之一。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 响应形式 | 服务器 SHOULD（应当）生成带有新 URI 的 `Location` 头；响应内容通常包含一段简短的超文本说明，并附有指向新 URI 的超链接。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 方法行为 | 出于历史原因，用户代理 MAY（可以）在重定向后的请求中把请求方法由 POST 改为 GET；308（永久重定向）则保留原方法。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 缓存 | 除非方法定义或显式的缓存控制另有规定，301 响应属于启发式可缓存。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 搜索引擎效果 | Googlebot 会跟随该重定向，索引流程将其作为信号，认定重定向目标应为规范 URL；PageRank 与入站链接等排名信号会跨 301 重定向传递。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)</sup><sup> • </sup><sup>[4](https://developers.google.com/search/help/crawling-index-faq)</sup> |
| 典型用途 | 站点迁移到新域名、合并重复 URL、合并两个网站，以及把用户从已删除的页面引导到新页面。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)</sup> |

## 定义与响应格式

301 状态码属于 3xx（重定向）类，该类表示用户代理必须采取进一步操作才能完成请求。<sup>[5](https://www.rfc-editor.org/rfc/rfc9110.pdf)</sup> 301 响应声明目标资源有了新的永久 URI，并建议具备链接编辑能力的用户代理可以永久地把对旧 URI 的引用替换为新 URI。规范指出，这一建议通常会被忽略，除非用户代理正在主动编辑引用、连接是安全的，且源服务器是被编辑内容的可信权威。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

一次典型的交互如下，取自 MDN 关于文档页面迁移的示例：<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)</sup>

```
GET /en-US/docs/AJAX HTTP/2
Host: developer.mozilla.org

HTTP/2 301
cache-control: max-age=2592000,public
location: /en-US/docs/Learn_web_development/Core/Scripting/Network_requests
content-type: text/plain; charset=utf-8

Moved Permanently. Redirecting to /en-US/docs/Learn_web_development/Core/Scripting/Network_requests
```

如果提供了 `Location` 头，即使用户代理并不理解该具体状态码，也可以（MAY）自动把请求重定向到所指的 URI。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## 方法变更与 308 替代方案

在 HTTP/1.0 中，301 与 302（Found，已找到）最初被定义为保留请求方法，这与它们在欧洲核子研究中心（CERN）的实现一致。早期用户代理对于应把 POST 请求重定向为 POST 还是 GET 意见不一，主流实践最终统一为把方法改为 GET。后来新增了 307（临时重定向）与 308（永久重定向），以明确表示保留方法的重定向；301 与 302 则被调整为允许把 POST 请求重定向为 GET。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

Fetch 标准遵循这一行为：当用户代理收到对 POST 请求的 301 响应时，会在后续的重定向请求中使用 GET。若要避免用户代理改动请求，应改用 308 状态码，因为 308 响应之后禁止更改方法。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)</sup>

## 缓存

301 响应属于启发式可缓存，即缓存可以在没有显式新鲜度信息的情况下存储并复用它，除非方法定义或显式缓存控制另有说明。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> MDN 把 301 列入可缓存的 HTTP 状态码，与 200、203、204、206、300、404、405、410、414、501 并列。<sup>[6](https://developer.mozilla.org/en-US/docs/Glossary/Cacheable)</sup> 由于 301 声明的是永久迁移，这种缓存通常是合意的，但这也意味着错误发出的 301 可能一直留在缓存中，直到过期。

## 在搜索引擎中的使用

Google 搜索对不同重定向类型区别对待。对于永久重定向（包括 301 与 308），Googlebot 会跟随重定向，索引流程将其作为信号，认定重定向目标应为规范 URL，因此搜索结果中显示的是新 URL。302、303、307 等临时重定向会被跟随，但不携带这一规范化信号，因此源页面可能仍留在索引中。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)</sup> 重定向是 Google 规范化过程中最强的信号之一，与 `rel="canonical"` 链接标注和站点地图收录并列，这些方法可以组合使用以增强效果。<sup>[7](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls?content_language=English)</sup>

Google 建议，只要页面在搜索结果中的 URL 发生变化，就应使用永久性的服务器端重定向；并指出 PageRank 或入站链接等排名信号会适当地跨 301 重定向传递，例如把两个域名合并到一个首选域名时。<sup>[4](https://developers.google.com/search/help/crawling-index-faq)</sup> 对于站点迁移，Google 建议使用 301、308 等 HTTP 永久重定向，并建议不要串联重定向：Googlebot 在一条链中最多可跟随 10 跳，但最好直接重定向到最终目的地，理想情况下不超过 3 跳、且少于 5 跳，因为链会增加延迟，而且并非所有用户代理都支持长链。<sup>[8](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes?rd=1&visit_id=637465664252572880-1678548209)</sup>

301 并不总是正确选择。对于把用户从原始 URL 重定向到变体 URL 的网站实验，Google 建议使用 302（临时）重定向而非 301，这样搜索引擎会把原始 URL 保留在索引中，而不会用测试页面取而代之。<sup>[9](https://developers.google.com/search/docs/crawling-indexing/website-testing)</sup> 配置错误或恶意的 3xx 重定向也可能造成问题：某些攻击会插入返回 HTTP 3xx 重定向的代码，指向恶意或垃圾内容，这可能使搜索算法把攻击者的 URL 选为规范 URL。<sup>[10](https://developers.google.com/search/docs/crawling-indexing/canonicalization-troubleshooting)</sup>

## 实现

服务器端重定向在服务器配置文件中设置，例如 Apache 上的 `.htaccess` 文件，或在 PHP 等服务器端脚本中设置重定向头。Google 的文档给出以下示例：<sup>[3](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)</sup>

PHP，在任何输出发送之前设置头：

```php
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://www.example.com/newurl');
exit();
```

Apache `mod_alias`，用于简单的永久重定向：

```
Redirect permanent "/old" "https://example.com/new"
```

Apache `mod_rewrite`，用于更复杂的规则：

```
RewriteEngine on
RewriteRule "^/service$" "/about/service" [R=301]
```

NGINX，使用 `return` 实现永久重定向：

```
location = /service {
    return 301 $scheme://example.com/about/service
}
```

如果无法使用服务器端重定向，可以退而使用 `meta refresh` 或 [JavaScript](https://www.edgepedia.org/zh/javascript) 等客户端重定向；Google 把即时 `meta refresh`（0 秒）解释为永久重定向，而延迟的则视为临时重定向。<sup>[8](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes?rd=1&visit_id=637465664252572880-1678548209)</sup><sup> • </sup><sup>[3](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)</sup>

## 相关状态码

301 属于一族重定向状态码，它们以永久性和方法处理方式相区分。302（已找到）表示临时迁移，与 301 一样，出于历史原因其后可能跟随 POST 到 GET 的方法变更；307（临时重定向）是保留方法的临时对应项，308（永久重定向）则是 301 的保留方法的永久对应项。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> MDN 把 308 概括为等同于 301，但不修改请求方法。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)</sup> 对于较新的 QUERY 请求方法，301 或 308 重定向意味着客户端向 `Location` 中的 URI 发送类似的 QUERY 请求，历史上的 POST 到 GET 变更不适用。<sup>[11](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/QUERY)</sup>

## References

1. [RFC 9110: HTTP Semantics, Section 15.4.2 (301 Moved Permanently), IETF](https://www.rfc-editor.org/rfc/rfc9110.html)
2. [301 Moved Permanently, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)
3. [Redirects and Google Search, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/301-redirects?rd=1&visit_id=639172018318163833-1177446114)
4. [FAQ: Google Search Crawling And Indexing, Google Search Central](https://developers.google.com/search/help/crawling-index-faq)
5. [RFC 9110: HTTP Semantics (PDF), IETF](https://www.rfc-editor.org/rfc/rfc9110.pdf)
6. [Cacheable, MDN Web Docs Glossary](https://developer.mozilla.org/en-US/docs/Glossary/Cacheable)
7. [How to specify a canonical URL with rel="canonical" and other methods, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls?content_language=English)
8. [Site Moves and Migrations, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes?rd=1&visit_id=637465664252572880-1678548209)
9. [A/B Testing Best Practices for Search, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/website-testing)
10. [Fix Canonicalization Issues, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/canonicalization-troubleshooting)
11. [QUERY request method, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/QUERY)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/http-301

English original: https://www.edgepedia.org/http-301
