HTTP 301
HTTP 301 Moved Permanently
The HTTP 301 Moved Permanently
redirect status response code indicates that the requested resource has been definitively moved to a new URL. This response informs clients that future requests for this resource should use one of the URLs provided in the Location
response header.
Details:
- Purpose: Signals a permanent redirection, meaning the old URL is no longer valid and should not be used again.
- Caching: This response is cacheable by default, allowing browsers and other clients to store the redirection and automatically use the new URL for subsequent requests. This is a crucial aspect of 301 redirects, minimizing server load and improving user experience.
- HTTP Method Preservation: While HTTP/1.0 did not require it, HTTP/1.1 specifies that user agents SHOULD NOT change the request method when automatically redirecting to the new URL. This means if the original request was a
POST
, the redirected request ideally remains aPOST
. However, browsers often implement this differently and may changePOST
requests toGET
when following 301 redirects. - Search Engine Optimization (SEO): Search engines treat 301 redirects as a strong signal that content has permanently moved. They typically transfer most of the "link juice" (ranking power) from the old URL to the new URL, making 301 redirects a critical tool for website migrations and URL structure changes.
- Difference from 302: It is vital to distinguish between a 301 and a 302 (Found) redirect. A 301 is for permanent moves, while a 302 is for temporary moves. Using the incorrect redirect type can negatively impact SEO and user experience.
- Location Header: The
Location
response header must be included in a 301 response. This header specifies the new URL where the resource can be found.