# HTTP Redirect 参考

URL: https://caijiao.org/reference/http/redirect
Source: docs/reference/http/redirect.md
Description: HTTP Redirect Reference，整理 301、302、303、307、308 的区别、Location 响应头、SEO 场景、Nginx 示例和常见错误。

HTTP Redirect 用于把一个 URL 引导到另一个 URL。它常见于 HTTP 跳 HTTPS、旧路径迁移、新域名上线、A/B 测试和登录跳转。

## 常见状态码

| 状态码 | 类型 | 是否通常保留请求方法 | 常见场景 |
| --- | --- | --- | --- |
| `301` | 永久重定向 | 不一定 | URL 永久迁移、HTTP 跳 HTTPS |
| `302` | 临时重定向 | 不一定 | 活动页、A/B 测试、临时跳转 |
| `303` | 临时重定向 | 转为 GET | 表单提交后跳转结果页 |
| `307` | 临时重定向 | 是 | 临时迁移但需要保留 POST 等方法 |
| `308` | 永久重定向 | 是 | 永久迁移且需要保留请求方法 |

## 响应示例

```http
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-path
```

## Nginx 示例

```nginx
return 301 https://$host$request_uri;
```

## SEO 使用建议

- 永久迁移用 `301` 或 `308`。
- 临时活动和 A/B 测试用 `302`，避免把临时目标当成永久规范地址。
- 尽量直接跳到最终目标，减少重定向链。
- 同时更新站内链接、canonical 和 sitemap，避免信号互相矛盾。

## 常见错误

- 临时活动误用 `301`，导致搜索引擎把目标页当作长期替代。
- 多层跳转，例如 HTTP -> HTTPS -> www -> 新路径，增加延迟和排查难度。
- 重定向到不相关页面，用户和搜索引擎都难以理解迁移关系。
- 只做前端 JavaScript 跳转，服务端仍返回 200，SEO 信号不够清晰。

## 相关内容

- [HTTP Reference](/reference/http/)
- [HTTP 状态码总览](/reference/http/status-codes)
- [301 和 302 重定向怎么选](/how-to/seo-website/301-vs-302)
- [HTTP 如何跳转到 HTTPS](/how-to/seo-website/http-to-https)
- [Nginx HTTPS 与 SSL 证书配置](/nginx/https-ssl)
- [Google Search Central 重定向文档](https://developers.google.com/search/docs/crawling-indexing/301-redirects)
- [Google Search Central 站点迁移](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes)
