HTTP 301 explained

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:

Examples

Client request:GET /index.php HTTP/1.1Host: www.example.orgServer response:HTTP/1.1 301 Moved PermanentlyLocation: https://www.example.org/index.asp

Using an .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 OnRewriteCond % offRewriteCond % ^www\.(.*)$ [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond % onRewriteCond % ^www\.(.*)$ [NC]RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteEngine OnRewriteCond % 80RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Static HTML

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

Home

Using programming languages

Here is an example using Perl CGI.pm:print redirect("https://example.com/newpage.html");Here is an example using a PHP redirect:

Here is one way to redirect using Express.js:app.all("/old/url", (req, res) =>);

Caching server

Equivalently simple for an nginx configuration:location /old/url

Search engines

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

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

Browser handling

Server side

Comparison with other status codes

Location header

Impact on SEO

Common pitfalls

See also

Notes and References

  1. Fielding. etal . 10.3.2 301 Moved Permanently . 2616 . 61 . IETF . June 1999 . 10.3.2.
  2. Web site: Site Move Tool . Bing Webmaster Help & How-to .
  3. Web site: 301 redirects . Google Webmaster Tools Help .
  4. https://www.301-redirect.online/htaccess-rewrite-generator#insert 301 redirect for Apache .htaccess : mod_rewrite
  5. https://http-statuscode.com/en/blog/SEO_and_HTTP_status_codes:_A_comprehensive_analysis SEO and HTTP status codes: A comprehensive analysis
  6. https://ahrefs.com/blog/301-redirects/ 301 Redirects Explained: How They Impact SEO