How and when to use HTTP 301 redirects

When your browser client connects to an web site over the internet, it sends associate HTTP request to it web site for the information it is searching for. The web site then responds with associate HTTP status code to inform the client however it’ll deal with its request. The foremost common status code is 200, which implies the request was received and is being processed by the server.

In the case wherever the situation of a resource has changed, the HTTP status codes 301 and 302 are used. there’s a very important distinction between these 2 status codes: 301 means that the resource the client is searching for has moved permanently, whereas 302 means that the resource has moved locations temporarily. In each cases, the server returns the new location wherever it will 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 because the new permanent location wherever it will find it, and can 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 can still request the resource from the old URL in future requests.

A question we have a tendency to get usually from involved web site owners is once it’s applicable to use a 301 redirect. even as clients use HTTP status codes to grasp the context of a server response, thus do search engines. If the location of a page or resource has permanently or indefinitely changed, that’s once it’s appropriate to use a 301 redirect. However, if the location of a resource has only changed temporarily – and there are several situations wherever this may happen – then you ought to use a 302 redirect. it’s vital to never use the incorrect status code, as a result of search engines that see a 301 redirect can take into account the new URL given by the server because the permanent new location for the resource it’s requesting.

It may additionally take time for search engines to update its index to reflect changes you’ve made to the location of pages on your web site, thus don’t expect it to happen directly or straight off after a search engine bot/spider crawls your website.

The most vital variety of redirect to pay attention to is that if you wish to change domains. A 301 redirect not solely tells search engines your site’s new location, it additionally maximises the probabilities search engines can transfer your domain’s authority and rankings to your new domain. Otherwise, it’ll be treated as a new web site which implies you’ll be starting from scratch with no authority and low rankings. In all cases, there’s sadly no guarantee that your domain’s authority and rankings can transfer over to your new domain, and Google do warn they’re under no obligation to do so.

If you need to change domains, you should only begin putting 301 redirects in place once you have got allowed enough time for nameserver propagation if your new domain had nameservers previously set. you have to additionally confirm the internal pages of your web site have 301 redirects in place to your new domain. You are not required to create an Apache rule for every page on your web site if they’re going to be within the same location under your new domain – in that case a typical rule is used like this (modify it according to your needs):

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.example.com [NC]
RewriteRule ^(.*)$ http://www.new.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.old.example.com [NC]
RewriteRule ^(.*)$ http://www.new.example.com/$1 [L,R=301]

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

Redirect 301 /old-page.php http://www.example.com/new-page.php