How and when to use HTTP 301 redirects

When your browser client connects to a website over the Internet, it sends an HTTP request to that website for the information it is looking for. The website then responds with an HTTP status code to inform the client how it will deal with its request. The most common status code is 200, which means the request was received and is being processed by the server.

In the case where the location of a resource has changed, the HTTP status codes 301 and 302 are used. There is an important difference between these two status codes: 301 means the resource the client is looking for has moved permanently, whereas 302 means the resource has moved locations temporarily. In both cases, the server returns the new location where it can find the information it is looking for.

If the client receives a 301 response, the client interprets the new URL for that resource provided by the server as the new permanent location where it can find it, and will use the new location in future requests. In 302 responses, the client considers the new URL provided by the server temporary for that request only, and will continue to request the resource from the old URL in future requests.

A question we get often from concerned website owners is when it is appropriate to use a 301 redirect. Just as clients use HTTP status codes to understand the context of a server response, so do search engines. If the location of a page or resource has permanently or indefinitely changed, that is when it is appropriate to use a 301 redirect. However, if the location of a resource has only changed temporarily – and there are many situations where this can happen – then you should use a 302 redirect. It is important to never use the wrong status code, because search engines that see a 301 redirect will consider the new URL given by the server as the permanent new location for the resource it is requesting.

It may also take time for search engines to update its index to reflect changes you’ve made to the location of pages on your website, so don’t expect it to happen right away or immediately after a search engine bot/spider crawls your website.

The most important type of redirect to pay attention to is if you need to change domains. A 301 redirect not only tells search engines your site’s new location, it also maximises the chances search engines will transfer your domain’s authority and rankings to your new domain. Otherwise, it will be treated as a new website which means you’ll be starting from scratch with no authority and low rankings. In all cases, there is unfortunately no guarantee that your domain’s authority and rankings will transfer over to your new domain, and Google do warn they are under no obligation to do so.

If you do need to change domains, you should only start putting 301 redirects in place once you have allowed enough time for nameserver propagation if your new domain had nameservers previously set. You should also make sure the internal pages of your website have 301 redirects in place to your new domain. You do not need to create an Apache rule for each page on your website if they will be in the same location under your new domain – in that case a common rule can be used like this (modify it according to your needs):

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

If the location of your site’s pages are changing along with your new domain, you will need to have individual 301 redirects in place for each affected page. For example:

Redirect 301 /old-page.php

Powered by BetterDocs