What is a 301 Redirect & When Should You Use One?

Find out some of the most commonly used types of redirections and get the optimal strategy for implementing a 301 redirect on any website.

Test 301 redirect for a specific URL
img-border How to do 301 redirect with htaccess

Table of contents



What is a redirect?


It is a way to redirect site users and search engines to a different URL than the one they originally requested. Below are descriptions of some of the most commonly used types of redirection.


301 Moved Permanently

301 redirect is a permanent redirect, which transfers about 90-99% of link juice. This redirect indicates that the page has been moved to a new address and the old URL should be considered out-of-date.


302 Found (HTTP 1.1) / Moved Temporarily (HTTP 1.0)

302 redirect – temporary redirect. This redirect transmits 0% of link juice and, in most cases, should not be used. At the moment, the Internet works under the HTTP protocol, which determines how to manage URLs. In two versions of this protocol, this server reply has a different response status:

  • HTTP 1.0: 302 server response is “Moved Temporarily” – the current document is temporarily moved to a different URL.
  • HTTP 1.1: there was a change in the server’s response to “Found” – the current document was found.


307 Moved Temporarily (HTTP 1.1 Only)

307 redirect in the HTTP 1.1 protocol became the receiver of the 302 redirect. While the main search bots will consider it as an analog-302, for almost all cases, it’s best to use 301. The exception to this rule is when the content moved only temporarily (for example, during tech maintenance) and the search engines already understand, that your server is compatible with HTTP 1.1. However, since it is hard to determine whether the search engines really understood that your server is compatible with this new protocol, it is better to use a 302 redirect for content that was temporarily moved.


Other types of redirects

There are also other kinds of redirects: using Meta Refresh or JavaScript – which are executed at the page level, and not at the server level. Here’s what a typical Meta Refresh redirect looks like:

However, these redirects are desirable to use extremely rare, because they can be used by spammers and doorways. Also, when using these redirects, the link juice is almost not transmitted.

Examples of using are below.


Canonization of a site’s domain or how to stick a domain together?


To glue a domain from www to without www:

RewriteCond %{HTTP_HOST} ^www.site\.com$ [NC]
RewriteRule ^(.*)$ Http://site.com/$1 [R=301,L]

For gluing together with without www on www:

RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ Http://www.site.com/$1 [R=301,L]

In order to correctly choose on which option to paste, it is advisable to take into account:

  • what options are more in the top
  • what options lead to more pages in the index


Slash canonicalization at the end of the URL

When designing a site it is important to decide on the format using the slash at the end of the URL, since for search engines there are 2 URLs of the form:

  • http://www.site.com/cat1/
  • http://www.site.com/cat1

are different. Therefore, after you have decided on the site, then you need to prescribe the following redirects

To remove a slash at the end:

RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $ 1 [L,R =301]

To add a slash to the end of the address bar:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

Redirection of one page to another page:

Redirect 301 /oldpage.html http://www.site.com/newpage.html

Redirect for the duplicates of the main page

This code ensures that any home page address that includes multiple versions of direct links to the page name, for example, default.htm or index.html, will be redirected to the canonical homepage, http://www.site.com:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index|main)\.(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://www.site.com/$1 [L,R=301]


Redirect directory

If the catalog structure displayed in the URL, then if you do the redirection, you will also have to change the URL accordingly. In this case, you need to write the following redirect:

RewriteRule ^(.*)/old-catalog/(.*)$ $1/new-catalog/$2 [R=301,L]

But, if the URL of the old catalog starts immediately after the domain: www.site.com/old-catalog/, then you need to use the following code

RewriteRule old-catalog /(.*) / old-catalog /$1 [R=301,L]


Redirect when changing file extensions

If you suddenly moved to another platform or CMS and at the same time the URLs extension changed only, then, in this case, you need to use such redirect.

RedirectMatch 301 (.*)\.php$ http://www.site.com$1.html

Usage examples to protect the site from multiple page duplicates


Redirect from different domains and subdomains

If you bought several domains in different domain zones or developed a new site and attach it on a subdomain, and forgot to close this subdomain from indexing, you must redirect to the primary domain:

RewriteCond %{HTTP_HOST} !^www\.site\.com
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

Thus, all domains such as www.site.ru, www.site.net, test.site.com will be redirected to www.site.com.


How to remove multiple slashes / dashes in a URL

Sometimes “by chance” the URL may include several slashes, for example, www.site.com/catalog////page-1.html. Here it is necessary to do 301 redirect per page with one slasher www.site.com/catalog/page-1.html:

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

Likewise, you can put together several dashes into one in the URL: from www.site.com/catalog/page-1.html at www.site.com/catalog/page-1.html:

RewriteCond %{REQUEST_URI} ^(.*)--(.*)$
RewriteRule . %1-%2 [R=301,L]


How to make a redirect from any URL to URL but only in lowercase?

Since, lowercase is taken into account by search engines, when designing a site it is desirable to add all URLs in lowercase. However, if you initially missed this point, it’s best to use the following redirect code at the php script level:

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['HTTP_HOST'] . $lowerURI);


How to move to a new domain? The optimal strategy for 301 redirects


The most favorable strategy for moving to a new domain, taking into account the conditions of the two major search engines – Runet Yandex and Google:

  • 301 redirect from the old site to the new one.
  • whereas we do not do a redirect for the robots.txt file, but we assign the Host directive to the new domain.

Then the code for setting up a redirect on the old site can look like this:

RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC]
RewriteRule ^([^/]+) $1 [L]
RewriteCond %{HTTP_HOST} !^www\.site\.com
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

and the robots.txt file for the old site:

User-agent: Google
Host: newsite.com


Generation of 301 redirects

If you are not a tech-savvy, then you can use the services of generating basic redirects:

  • http://www.webconfs.com/htaccess-redirect-generator.php
  • http://www.rapidtables.com/web/tools/redirect-generator.htm

On such services, you can only substitute your own data and immediately get the ready code for redirects between domains, directories or URLs.


How to check 301 redirects?

After each logical change of the redirect 301 work, it is necessary to check the site’s operability:

  • Does the site actually work?- Go to the main page
  • go through the main sections and pages of the site

Also, for more thorough testing of redirects, you can use the following services:

  • http://bertal.ru – as much as possible detailed information on the server’s answers.
  • http://www.internetmarketingninjas.com/header-checker/.


How and when to use the 301 redirect vs. Canonical?


Although there are some nuances, Google provides some clear rules, so that he understands exactly what we want to say. In simple words, here’s how the search engines understand these instructions:


301 – Hey, Search Engines: my page is no longer here, and it’s moved to a new page. Please delete the old page from the index and transfer its link juice to a new page.


Canonical – Hey, Search Engines (for most search engines): I have several versions of this page (or content), please index only the version of the page that is canonical. I will keep other pages accessible to people so that they can see them, but, Search Engine, do not include them in your index and please transfer the link juice to my preferred page.


When is it better to use 301 redirects?

  • By default – it is the preferred method
  • For pages – if the page has permanently moved or has been replaced by a new address
  • For domains – if the site has moved to a new domain (site’s sale, rebranding, etc.
  • For 404 pages and content that has lost its relevance (subject to appropriate content). For example, if you remove a product from a specific directory, you can make a redirect to a similar product, or to the URL category that this product belongs to.


When is it better to use rel=”canonical”?

  • When 301 redirects cannot be performed, or their implementation will take too much time
  • Duplicate content, but you want to keep both pages for people (for example, show different clothes on different URLs)
  • Pages with several different URL, in essence, one page (for example, catalog sorting, tracking of partner links, etc.
  • Cross-domains, when both sites are similar, but similar content should be added on each of the domains.


In general, both options allow keeping the link juice and they will be interpreted similarly by Google. However, in general, 301-redirect is the preferred method.


Mistakes when using redirects


Any multi-step redirect. If possible, it is advisable not to allow multi-step redirects, so that it works more quickly, and a maximum of link juice is transmitted.

Using the wrong type of redirects. When choosing the type of redirect, it is necessary to take into account the nuances of each of them.

Implementation of internal redirects without changing links to new addresses. After performing all redirects on your site, you need to check that every page of your site already refers to a new one, and don’t add links to the pages from which the redirection occurs on the site.

Redirect to irrelevant pages / content. Redirection should always direct to the most relevant page: either on a similar page or on a branch of the catalog/section to which this page belonged.

Wrong choice of using rel=canonical vs. 301 redirect. See above.

Redirect, the end point of which is not the 200th page. Redirection should lead to a properly functioning page with 200 server responses. Otherwise, it is advisable not to confuse the search robots and give 404 an answer.

Redirect robots.txt. Since, for example, you need to register the Host directive for Yandex when domains’ adhesion.

We hope that this guide will become a cheat sheet and a great assistant to use the 301 redirect for your site.

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)

The password link was sent to you by email

The password changed