Access the NEW Basecamp Support Portal

HTTP 301

« Back to Glossary Index

HTTP 301 Examples
– Client request: GET /index.php HTTP/1.1Host: www.example.org
– Server 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: Redirect 301 /calendar.html /calendar/Redirect 301 /not_found.html /
– Example of 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]
– Example of a custom directory redirect using an index.html file:
– meta http-equiv=refresh content=0; url=/
– a href=/Home/a

Using Programming Languages
– Example of using Perl CGI.pm for redirection: print redirect(https://example.com/newpage.html);
– Example of using PHP redirect: ?phpheader(Location: https://example.com/newpage.html, true, 301);exit;
– Example of redirecting using Express.js:
– app.all(/old/url, (req, res) = {res.redirect(301, /new/url);});

Caching Server
– Example of a simple nginx configuration for redirection:
– location /old/url {return 301 /new/url;}

Search Engines
– Both Bing and Google recommend using a 301 redirect to change the URL of a page in search engine results.
– The URL change should be permanent and not expected to change again soon.

Additional Information
– HTTP 301 is a status code used for permanent URL redirection.
– It is commonly used when a website’s URL structure changes or when a page is moved to a new location.
– The 301 redirect informs both users and search engines that the requested page has been permanently moved to a new location.
– It is important to use a 301 redirect instead of other types of redirects like 302 or meta refresh, as it ensures that search engines will update their indexes with the new URL.
– The examples provided showcase different methods of implementing a 301 redirect, including using .htaccess files, programming languages, caching servers, and recommended practices for search engine optimization.

HTTP 301 (Wikipedia)

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:

  • 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.
« Back to Glossary Index

Request an article

Please let us know what you were looking for and our team will not only create the article but we'll also email you to let you know as soon as it's been published.
Most articles take 1-2 business days to research, write, and publish.
Content/Article Request Form

Submit your RFP

We can't wait to read about your project. Use the form below to submit your RFP!
Request for Proposal

Contact and Business Information

Provide details about how we can contact you and your business.


Quote Request Details

Provide some information about why you'd like a quote.