fbpx
Wikipedia

HTTP 301


On the World Wide Web, 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 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.

RFC 2616[1] 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 edit

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 an .htaccess file edit

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 %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R,L] 

Static HTML edit

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

<meta http-equiv="refresh" content="0; url=/" /> <p><a href="/">Home</a></p> 

Using programming languages edit

Here is an example using Perl CGI.pm:

print redirect("https://example.com/newpage.html"); 

Here is an example using a PHP redirect:

<?php header("Location: https://example.com/newpage.html", true, 301); exit; 

Here is one way to redirect using Express.js:

app.all("/old/url", (req, res) => {  res.redirect(301, "/new/url"); }); 

Caching server edit

Equivalently simple for an nginx configuration:

location /old/url {  return 301 '/new/url'; } 

Search engines edit

Both Bing and Google recommend using a 301 redirect to change the URL of a page as it is shown in search engine results, providing that URL will permanently change and is not due to be changed again any time soon.[2][3]

Technical Details edit

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

Browser Handling edit

  • 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 edit

  • 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.[4]


Comparison with Other Status Codes edit

  • 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.[5]
  • 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 edit

  • 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 edit

  • 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.[6]
  • Indexing Delays: There might be a lag before search engines recognize the redirect and update their indexes accordingly.

Common pitfalls edit

  • 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 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 edit

References edit

  1. ^ Fielding; et al. (June 1999). 10.3.2 301 Moved Permanently. IETF. p. 61. sec. 10.3.2. doi:10.17487/RFC2616. RFC 2616.
  2. ^ "Site Move Tool". Bing Webmaster Help & How-to.
  3. ^ "301 redirects". Google Webmaster Tools Help.
  4. ^ 301 redirect for Apache .htaccess : mod_rewrite
  5. ^ SEO and HTTP status codes: A comprehensive analysis
  6. ^ 301 Redirects Explained: How They Impact SEO

http, world, wide, http, response, status, code, moved, permanently, used, permanent, redirecting, meaning, that, links, records, returning, this, response, should, updated, should, provided, location, field, included, with, response, redirect, considered, bes. On the World Wide Web 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 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 RFC 2616 1 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 Contents 1 Examples 1 1 Using an htaccess file 1 2 Static HTML 1 3 Using programming languages 1 4 Caching server 1 5 Search engines 2 Technical Details 2 1 Browser Handling 2 2 Server side 2 3 Comparison with Other Status Codes 2 4 Location Header 2 5 Impact on SEO 2 6 Common pitfalls 3 See also 4 ReferencesExamples editClient 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 an htaccess file edit 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 HTTPS off RewriteCond HTTP HOST www NC RewriteRule http 1 1 R 301 L RewriteCond HTTPS on RewriteCond HTTP HOST www NC RewriteRule https 1 1 R 301 L RewriteEngine On RewriteCond SERVER PORT 80 RewriteRule https example com 1 R L Static HTML edit A custom directory redirect using an index html file lt meta http equiv refresh content 0 url gt lt p gt lt a href gt Home lt a gt lt p gt Using programming languages edit Here is an example using Perl CGI pm print redirect https example com newpage html Here is an example using a PHP redirect lt php header Location https example com newpage html true 301 exit Here is one way to redirect using Express js app all old url req res gt res redirect 301 new url Caching server edit Equivalently simple for an nginx configuration location old url return 301 new url Search engines edit Both Bing and Google recommend using a 301 redirect to change the URL of a page as it is shown in search engine results providing that URL will permanently change and is not due to be changed again any time soon 2 3 Technical Details editThe HTTP 301 status code has several technical nuances that developers should be aware of when implementing and managing redirections Browser Handling edit 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 edit 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 4 Comparison with Other Status Codes edit 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 5 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 edit 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 edit 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 6 Indexing Delays There might be a lag before search engines recognize the redirect and update their indexes accordingly Common pitfalls edit 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 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 editHypertext Transfer Protocol List of HTTP status codes URL redirectionReferences edit Fielding et al June 1999 10 3 2 301 Moved Permanently IETF p 61 sec 10 3 2 doi 10 17487 RFC2616 RFC 2616 Site Move Tool Bing Webmaster Help amp How to 301 redirects Google Webmaster Tools Help 301 redirect for Apache htaccess mod rewrite SEO and HTTP status codes A comprehensive analysis 301 Redirects Explained How They Impact SEO Retrieved from https en wikipedia org w index php title HTTP 301 amp oldid 1211603045, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.