Contents
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 states that:
Examples
Client request: Server response:
Using a .htaccess file
To fix problems with non-existing files or directories using a distributed .htaccess file: Here is an example using a .htaccess file to redirect a non-secure URL to a secure address without the leading "www":
Static HTML
A custom directory redirect, using an index.html file:
Using programming languages
Here is an example using Perl CGI.pm: Here is an example using a PHP redirect: Here is one way to redirect using Express.js:
Caching server
Equivalently simple for an nginx configuration:
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 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
Server side
Comparison with other status codes
Location header
Impact on SEO
Common pitfalls
This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.
Wikipedia® is a registered trademark of the
Wikimedia Foundation, Inc.
Bliptext is not
affiliated with or endorsed by Wikipedia or the
Wikimedia Foundation.