HTTPQUERY
中文

301 Moved Permanently

Usage

When the 301 Moved Permanently status code is received, clients are expected to update stored links to the new URI. The new URI is specified by the Location header and is used by the client for automatic redirection.

This response is common when servers migrate to a new domain or reorganize their internal file structure with no plan to revert to the former URI.

Method change

User agents are permitted to change POST to GET on a 301 redirect for historical reasons. Most browsers do exactly this, making the method change a de facto standard behavior. The 308 status code was created specifically to guarantee method preservation without ambiguity. For APIs and modern applications, prefer 308 for permanent redirects when the original method must be kept.

Keep 301 redirects active for at least one year, ideally indefinitely. Google recognizes 301s quickly but full signal transfer takes weeks. Browsers cache 301 responses aggressively based on Cache-Control directives. Without explicit cache headers, the redirect persists in browser cache indefinitely. Removing a 301 server-side does not clear cached redirects in browsers.

Example

The client requests an HTML resource. The server responds with 301 Moved Permanently and includes the new URI in the Location header. A message body suggests updating bookmarks, though modern browsers redirect immediately.

Request

GET /news.html HTTP/1.1
Host: example.com

Response

HTTP/1.1 301 Moved Permanently
Location: http://example.com/feeds/news.html
Content-Type: text/html; charset=UTF-8
Content-Length: 150

<h1>The Newsfeed has moved</h1>
<body>
The newsfeed has moved permanently to
<a href=/feeds/news.html>here</a>.
Please update your bookmarks.
</body>

Code references

.NET

HttpStatusCode.MovedPermanently

Rust

http::StatusCode::MOVED_PERMANENTLY

Rails

:moved_permanently

Go

http.StatusMovedPermanently

Symfony

Response::HTTP_MOVED_PERMANENTLY

Python3.5+

http.HTTPStatus.MOVED_PERMANENTLY

Java

java.net.HttpURLConnection.HTTP_MOVED_PERM

Apache HttpComponents Core

org.apache.hc.core5.http.HttpStatus.SC_MOVED_PERMANENTLY

Angular

@angular/common/http/HttpStatusCode.MovedPermanently