HTTP 301
   HOME

TheInfoList



OR:

On the
World Wide Web The World Wide Web (WWW or simply the Web) is an information system that enables Content (media), content sharing over the Internet through user-friendly ways meant to appeal to users beyond Information technology, IT specialists and hobbyis ...
, HTTP 301 is the HTTP response status code for 301 Moved Permanently. It is used for permanent redirecting, meaning that links or records returning this response should be updated. The new
URL A uniform resource locator (URL), colloquially known as an address on the Web, is a reference to a resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identi ...
should be provided in the Location field, included with the response. The 301 redirect is considered a best practice for upgrading users from HTTP to
HTTPS Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It uses encryption for secure communication over a computer network, and is widely used on the Internet. In HTTPS, the communication protoc ...
. RFC 2616 states that: * If a client has link-editing capabilities, it should update all references to the Request URL. * The response is cacheable unless indicated otherwise. * Unless the request method was HEAD, the entity should contain a small hypertext note with a hyperlink to the new URL(s). * If the 301 status code is received in response to a request of any type other than GET or HEAD, the client must ask the user before redirecting.


Examples

Client request: GET /index.php HTTP/1.1 Host: www.example.org Server response: HTTP/1.1 301 Moved Permanently Location: https://www.example.org/index.asp


Using a .htaccess file

To fix problems with non-existing files or directories using a distributed .htaccess file: Redirect 301 /calendar.html /Calendar/ Redirect 301 /not_found.html / Here is an example using a .htaccess file to redirect a non-secure URL to a secure address without the leading "www": RewriteEngine On RewriteCond % off RewriteCond % ^www\.(.*)$ CRewriteRule ^(.*)$ http://%1/$1 =301,L RewriteCond % on RewriteCond % ^www\.(.*)$ CRewriteRule ^(.*)$ https://%1/$1 =301,L RewriteEngine On RewriteCond % 80 RewriteRule ^(.*)$ https://example.com/$1 ,L


Static HTML

A custom directory redirect, using an index.html file:

Home


Using programming languages

Here is an example using
Perl Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language". Perl was developed ...
CGI.pm: print redirect("https://example.com/newpage.html"); Here is an example using a
PHP PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. ...
redirect: Here is one way to redirect using Express.js: app.all("/old/url", (req, res) => );


Caching server

Equivalently simple for an
nginx (pronounced "engine x" , stylized as NGINX or nginx) is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Russian developer Igor Sysoev and publicly released in 20 ...
configuration: location /old/URL


Search engines

Both
Bing Bing most often refers to: * Bing Crosby (1903–1977), American singer * Microsoft Bing, a web search engine Bing may also refer to: Food and drink * Bing (bread), a Chinese flatbread * Bing (soft drink), a UK brand * Bing cherry, a varie ...
and
Google Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
recommend using a 301 redirect to change the URL of a page as it is shown in search engine results, providing that the URL will permanently change and is not due to be changed again any time soon.


Technical details

The HTTP 301 status code has several technical nuances that developers should be aware of when implementing and managing redirections:


Browser handling

* Caching Behavior: Many web browsers cache 301 redirects. This means that once a user's browser encounters a 301 redirect, subsequent requests to the original URL will be automatically directed to the new URL without contacting the server. * Updating Bookmarks: Browsers may update bookmarks to reflect the new URL after encountering a 301 redirect.


Server side

* Apache: Apache has mod_alias and mod_rewrite to handle 301 redirects. Using both often results in unpredictable behavior because modules do not respect other module rules.


Comparison with other status codes

* 302 Found: Unlike a 301, a 302 status code indicates a temporary redirect. Search engines might not pass the SEO value to the new URL. * 307 Temporary Redirect: Like 302, but guarantees that the method and the body will not be changed when the redirected request is made. * 303 See Other: Used when the result of a POST or another non-idempotent request method is a resource that should be retrieved using a GET.


Location header

* Mandatory Inclusion: The new URL should always be provided in the "Location" field when a 301 redirect is sent. Omitting the Location header will confuse browsers and may result in unexpected behavior. * Absolute URL Usage: While relative URLs might be accepted by some browsers, using absolute URLs in the Location header is the standard and ensures consistent behavior across all user agents.


Impact on SEO

* Link Equity Transfer: Search engines typically transfer a majority of the link equity (or “link juice”) from the source URL to the target URL for 301 redirects.301 Redirects Explained: How They Impact SEO
/ref> * Indexing Delays: There might be a lag before search engines recognize the redirect and update their indexes accordingly.


Common pitfalls

* Multiple Redirects: Using multiple 301 redirects in succession (A to B, then B to C) can lead to increased page load times and may dilute SEO value. * Mixed Content Issues: When a redirecting from HTTP to HTTPS, ensure that all resources (images, scripts, stylesheets) on the page are also loaded over HTTPS to prevent mixed content warnings.


See also

*
Hypertext Transfer Protocol HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
*
List of HTTP status codes Hypertext Transfer Protocol (HTTP) response status codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request for Comments (RFCs), other specifications, and some additional codes us ...
*
URL redirection URL redirection, also called URL forwarding, is a World Wide Web technique for making a web page available under more than one URL address. When a web browser attempts to open a URL that has been redirected, a page with a different URL is opened. ...


References

{{Reflist Hypertext Transfer Protocol status codes