About redirects

What is a redirect?

A redirect is a way to show search engines new URL instead of the one they previously crawled. Below are descriptions of some of the most commonly used types of redirects.

301 Moved Permanently

301 redirect is a permanent redirect that transfers about 90-99% of the reference weight. This redirect indicates that the page has been moved to the new address and the old url should be considered obsolete.

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

302 redirect - temporary redirect. This redirect conveys 0% of the reference weight and, in most cases, should not be used.  the Internet works on so called HTTP protocol, which defines how work with URLs.  There are 3 versions of this protocol, and server responses have a different response status:

- HTTP 1.0: server responses 302 - “Moved Temporarily” that means URl moved to another URL, but maybe, not permanently .

- HTTP 1.1: server responses 302 - “Found” - the url was found.

307 Moved Temporarily (HTTP 1.1 Only)

A 307 redirect to HTTP 1.1 has become the receiver of a 302 redirect. While the main search bots will begin to consider it as an analogue of 302, for almost all cases, it is best to use 301. The exception to this rule is when the content really moved only temporarily (for example, during maintenance) and search engines already understand That your server is compatible with HTTP 1.1. But, since it is almost impossible to determine whether search engines really understood that your server is compatible with certain protocol, it is better to use 302 redirect for temporarily moved pages.

Other types of redirects

There are also other types of redirects: Meta Refresh or using JavaScript - which run at the page level, and not at the server level. Here is common Meta Refresh redirect:

 < meta http-equiv="refresh" content="2;URL=http:/example.comsite">

But, it is desirable to use these redirects extremely rarely, as spammers and doorwayers very much like to abuse them. In addition, when using these redirects, the reference weight is almost not transmitted. 
Examples of using

Canonization of the site domain or how to glue the domain?

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 with no www on with www:

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

In order to choose on which of the options to glue, it is advisable to look:

- how of these options are more in the top 
- for which of the options are there more pages in the index

The canonization of the slash at the end of the url

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

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

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

are different. Therefore, after you have decided how exactly you will be on the site, then you need to register the following redirects

To remove the 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 ]

Redirect one page to another page:

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

Redirect for duplicates of the main page

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

RewriteCond % {THE_REQUEST} ^ [AZ] { 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 ]

Directory Redirect

If your directory structure is displayed in the url-le, then if you do recatalogization, the url will change accordingly. In this case, you must register the following redirect:

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

But, if the url of the old catalog begins 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 the file extension

If you moved to another CMS and only the extension of the url was changed, then this redirect will help you

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

Examples of use to protect the site from multiple duplicate pages

Redirect from different domains and subdomains

If you purchased several domains or developed a new site on a subdomain, and forgot to close this subdomain from indexation, then you need to redirect to the main domain:

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

Thus, all domains of type www.site.ru, www.site.net, test.site.com will be redirected to the site www.site.com.

How to remove some slashes / dashes in urla

Sometimes “by accident” in urla may appear in several slashes, for example, www.site.com/catalog////page-1.html. In these, you need to make a 301 redirect to a page with one slasher www.site.com/catalog/page-1.html:

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

Similarly, you can glue together several hyphens in one URL: from www.site.com/catalog/page-1.html to www.site.com/catalog/page-1.html:

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

How to redirect from any URL to url only in lowercase

Since, by search engines, the case of letters is taken into account, then when designing a site, it is desirable that all URLs be in lower case. if you missed the moment, it is best to use the following code for a redirect at the level of a php script:

$ lowerURI = strtolower ($ _ SERVER [ 'REQUEST_URI' ]);
if ($ _ SERVER [ 'REQUEST_URI' ]! = $ lowerURI)
header ( "HTTP / 1.1 301 Moved Permanently" );
header ( "Location: http: //" . $ _SERVER [ 'HTTP_HOST' ]. $ lowerURI);
exit ();

How to move to a new domain? The optimal strategy 301 redirect

The optimal strategy for moving to a new domain, taking into account the wishes of the two main search engines on Yandex and Google, is:

- page 301 redirect from the old site to the new one. 
- while for the robots.txt file, the redirect is not done, but we write the Host directive to the new domain in it.

Then the code for setting up a redirect on the old site might 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: Yandex
Host: newsite.com

Generation of 301 redirects

If you are not very technically savvy, you can use the services of generating basic redirects:

On such online sites, you can paste your data and receive ready code for redirects.

How to check 301 redirect

After each change in the operation logic of the 301 redirect, it is necessary to check the performance of the site:

- Does the site work at all: go to the main page)

- walk through the main sections and pages of the site

You can also use the following services for more thorough checking of redirects development:

 - the most detailed information on server responses.


How and when is it better to use 301 redirect vs Canonical

Google has many unclear rules in order for it to understand what we wish to say. In a simple situation, here’s how these instructions are understood by search engines:

301 - Hey, Search Engines: my page is no longer here and it has permanently moved to a new page. Please remove the old page from the index and transfer its weight to the new page.

Canonical - Hey, Search Engines (like most search engines): I have several versions of this page (or content), please index only the version of the page that canonical is on. I’ll keep other pages accessible to people so they can see them, but Search Engine, don’t include them in your index and please transfer the weight to my preferred page.

When is it better to use 301 redirects

- Default is the preferred method.

- For pages: if the page is permanently moved or has been replaced with a new address

- For domains: if the site moved to a new domain (sale of the site, rebranding, etc.)

- For 404 pages and pages that has lost its relevance to appropriate content. For example, if a product was deleted, then you can redirect to a similar product, or to the url category to which the product belonged.

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

- When 301 redirects cannot be implemented, or their implementation will take too long

- Duplicate content, but you want to keep both pages for people (for example, show different clothing sizes on different URLs)

- Pages with several different urls of essentially one page (for example, sorting a directory, tracking partner links, ...)

- Cross-domains, when both sites are similar, but similar content should be left on each of the domains.


In general, both options allow you to save reference weight and they will be similarly considered by Google. But in general, 301 redirects are the preferred method.

Errors when using redirects

- Any multi-step redirect. If there is a possibility, then it is advisable not to allow multi-step redirects, so that it will work faster and give maximum reference weight.

- Using the wrong type of redirects. When choosing the type of redirect, you must consider the nuances of each of them.

- New internal redirects without changing the links to new urls. After implementing all the redirects on your site, you need to check that each page of your site already refers to a new one and inside the site you have no links to pages from which the redirect occurs.

- Redirect to pages with non-relevant content.

- To use rel = canonical instead 301 redirect.

- Redirect, the end point of which is not the 200th page. The redirect should lead to a properly working page with a 200 server response. Otherwise, it is advisable not to shoot down search robots and give 404 answers.