301 Moved Permanently

The HTTP 301 status code means a requested resource has been moved to a different URL once and for all.

301 Moved Permanently implies a resource has moved permanently to a different location (as indicated in the Location header), and from now on, clients should look for this resource in a new location:

HTTP/2 301 Moved Permanently
Location: https://example.com/new

POST requests

Like with 302 Found, some browsers have been incorrectly converting POST requests to GET requests upon encountering 301 status code. In such cases, POST data is discarded during a redirect. It goes against the HTTP spec, which states that the client should repeat the request with the same method and body.

If you want to be sure that the request will be retried with the same method and body, use 308 Permanent Redirect.

Request Method Permanent Temporary
Can change from POST to GET 301 302
Can’t change from POST to GET 308 307

Search engines

Upon encountering 301, search engines will eventually remove the page from their indexes and pass most of the domain authority (aka link juice), if not all, to the new page.

Try it yourself

Unlike browsers, most HTTP clients won’t follow redirects: you have to explicitly enable this behavior. For example, to follow redirects in curl, you will have to pass the -L, --location option:

curl -L http://tryhexadecimal.com

If your HTTP library doesn’t automatically follow redirects, you will have to extract the Location header and recursively follow it until you receive a non-3xx code.

Interested in no-nonsense technical guides?

No spyware, no promotional emails, or keyword-stuffed junk. I will only send you a single email when I've got something interesting to say. Unsubscribe anytime.

You can also subscribe to the Atom feed (it's like RSS, but better).