Why do you need a 301 redirect from a page. Notes and errors

If you want to properly configure 301 redirects on your site. Today we have prepared a step-by-step guide in which we tell and show all the details and nuances.

The 301 redirect guide has two parts:

- Visual detailed infographics

- An article with code examples and the manual itself (if you need an example code right away, it's better to skip right through the infographic)

What is a redirect?

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

301 Moved Permanently

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

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

302 redirect is a temporary redirect. This redirect transfers 0% of the link weight and, in most cases, should not be used. At the moment, the Internet runs over the HTTP protocol, which determines how to handle URLs. In two versions of this protocol, this server response has a different response status:

- HTTP 1.0: 302 server response is "Moved Temporarily" - the current document has been temporarily moved to a different URL.

- HTTP 1.1: the server response changed to "Found" - the current document was found.

307 Moved Temporarily (HTTP 1.1 Only)

A 307 redirect in the HTTP 1.1 protocol became the receiver of a 302 redirect. While the mainstream search bots will start to view it as an analogue of 302, for almost all cases it is best to use 301. The exception to this rule is when content has really only moved temporarily (for example, during maintenance) and search engines already understand that your server is HTTP 1.1 compliant. But since it is almost impossible to determine if the search engines have actually figured out that your server is compatible with this new protocol, it is best to use a 302 redirect for content that has been temporarily moved.

Other types of redirects

There are also other types of redirects - Meta Refresh or JavaScript - which are done at the page level, not at the server level. This is what a typical Meta Refresh redirect looks like:

RewriteCond% (HTTP_HOST) ^ www.site \\ .com $ RewriteRule ^ (. *) $ Http://site.com/$1

For gluing from without www to www:

RewriteCond% (HTTP_HOST) ^ site \\ .com $ RewriteRule ^ (. *) $ Http://www.site.com/$1

RewriteCond% (HTTP_HOST) ^ site \\ .com $ RewriteRule ^ (. *) $ Http://www.site.com/$1

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

- how of these options to be more in the top
- for which option has more pages in the index

Canonicalization of a slash at the end of an 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 exactly how you will have it on the site, then you need to register the following redirects

To remove the trailing slash:

RewriteCond% (REQUEST_FILENAME)! -F RewriteCond% (REQUEST_URI)! (. *) / $ RewriteRule ^ (. * [^ /]) $ $ 1 /

Redirect one page to another page:

RewriteCond% (THE_REQUEST) ^ (3.9) \\ / ([^ /] + /) * (default | index | main) \\. (Html \u200b\u200b| php | htm) \\ HTTP / RewriteRule ^ (([^ /] + /)*)(default|main|index)\\.(html|php|htm)$ http://www.site.com/$1

Directory redirect

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

RewriteRule old-catalog /(.*) / old-catalog / $ 1

Redirect when changing file extension

If you suddenly moved to another platform or CMS, and at the same time, only the extension of the urls has changed, then in this case such a redirect will help you

RewriteCond% (HTTP_HOST)! ^ Www \\ .site \\ .com RewriteRule ^ (. *) $ Http://www.site.com/$1

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

How to remove multiple slashes / dashes in url

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

RewriteCond% (REQUEST_URI) ^ (. *) - (. *) $ RewriteRule. % 1-% 2

How to redirect from any url to url only in lower case

Since search engines take into account the case of letters, then when designing a site, it is desirable that all urls be in lower case. However, if you initially missed this point, then it is best to use the following code for redirecting at the php-script level:

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

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

How do I move to a new domain? Optimal 301 redirect strategy

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

- page-by-page 301 redirect from the old site to the new one.
- in this case, we do not redirect the file, but write the Host directive to the new domain in it.

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

RewriteCond% (REQUEST_FILENAME) robots.txt $ RewriteRule ^ ([^ /] +) $ 1 [L] RewriteCond% (HTTP_HOST)! ^ Www \\ .site \\ .com RewriteRule ^ (. *) $ Http://www.site .com / $ 1 and the robots.txt file for the old site: User-agent: Yandex Disallow: Host: newsite.com

Generating 301 redirects

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

On such services, you can only substitute your own data and immediately receive a ready-made code for redirects between domains, directories or urls.

How to check 301 redirects

After each change in the logic of the 301 redirect, you need to check the site's performance:

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

- walk through the main sections and pages of the site

Also, for a more thorough check of redirection processing, you can use the following services:

How and when to use 301 redirects vs Canonical

While there are some nuances, Google provides some clear guidelines to help it understand exactly what we want to say. In a very simple situation, this is how search engines understand these instructions:

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

Canonical - Hey Search Engines (so for 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 will keep the other pages available for people to see, but Search Engine, do not include them in your index and please pass the weight to my preferred page.

When to use 301 redirects

- Default is the preferred method

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

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

- For 404 pages and content that has lost its relevance (subject to relevant content). For example, if a product has been removed from a specific catalog, then you can redirect to a similar product, or to the url category to which this product belonged.

When is the best time to use rel \u003d "canonical"?

- When 301 redirects cannot be implemented or take too long to implement

- Pages with several different urls, essentially one page (for example, sorting the directory, tracking affiliate links, ...)

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

Total

Errors when using redirects

- Any multi-step redirect. If possible, it is advisable not to allow multi-step redirects, so that it will work faster and transfer the maximum link weight.

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

- Implementation of internal redirects without changing links to new addresses. After implementing all redirects on your site, you need to check that each page of your site already links to the new one and inside the site you do not have links to the pages from which the redirect occurs.

- Redirect to irrelevant pages / content. It is always advisable to redirect to the most relevant page: either to a similar page, or to the branch of the directory / section to which this page belonged.

- Wrong choice of using rel \u003d canonical vs 301 redirect. See above.

We have released a new book, "Content Marketing on Social Media: How to Get Into the Heads of Subscribers and Fall in Love with Your Brand."

In this article, I wanted not only to give you the ready-made code, but also to sort everything out so that you can navigate both the technical component of the code and in conditions when it is worth or not to use it.

301 Permanent Redirect / 301 redirect ...

... is a redirection of a user to another page or domain address. This server response code means that the page and resource have moved permanently and are now available at a different address.

There are myths related to: for example, that the PR of the page is not transmitted during a redirect, but this myth was debunked by one of the Google webmasters John Mueller in your blog. Or that you can use 302 Temporary Redirect instead of a redirect.

There is a whole class of 3xx redirects. The most commonly used codes are 301 and 302 - they are like twins, which seem to be similar, but still differ. But for a search robot, these are two completely different people, and such server responses are interpreted in different ways:

  1. 301 Moved Permanently : permanent redirect. This code notifies that the resource has been permanently moved to a new address, deleting the previous domain. Needed for the final move to a new resource, a new CMS or for gluing pages.
  2. 302 Temporary Redirect: temporary redirect. Notifies about the temporary move of the site or its page Used for technical work on the site.

How these codes will affect the search results:

  • With a 301 redirect, a new URL starts to appear in the search results, but this may take some time. Google advises keeping the page status for a year.
  • When searching, the old URL of the page is saved, but after 6 months of using a 302 redirect, the search engine starts to consider it as a permanent 301, because temporary redirection is called “temporary” for a reason, and half a year is quite a long period.

Due to such mistakes of webmasters and the abuse of 302 redirects for unethical purposes, SEO experts strongly advise against using it on your site, because even for a slight suspicion of black SEO, you can get a serious fine. Let's better understand how you can set up a legal 301 redirect to

Htaccess file is an HTTP server configuration file like Apache. With its help, a large number of additional parameters and permissions of the web server are set, and it extends its rights only to the directory in which it is located and its child subdirectories.

The simplest exampleredirect: from site to site

Redirect / www.example.com

www.example.com is the site to which we redirect the user's request.

A slightly more complex example - if we want to redirect from pages of our site to another site. Or, for example, doredirect to home page.

Redirect / semantica site /

Redirect / semantica / blog site / blog

Redirect 301 / kernel site /

What does all this mean:

1 line - when accessing the page www.example.com/semantica, the site site /

2 line - when accessing http://www.example.com/semantica/blog the site / blog will be opened

3 line - the web server will give a 301 code about the permanent move to a new URL

Now that you roughly understand how it works, you can move on to more difficult tasks.

Complex redirects

For complex redirects, there is the mod_rewrite module, which is a URL conversion tool that uses. There are three important directives used for redirecting: RewriteCond, RewriteRule, and RewriteEngine.

  1. RewriteEngine enables or disables the conversion engine:

RewriteEngine on | off

The on-off position turns the module on and off.

2. RewriteCond - defines the condition of any rule under which the conversion occurs.Immediately after the directive, most often there are variables% (HTTP_HOST) and% (REQUEST_URI), which mean the server address (for example, example.ru) and the resource requested in the HTTP request line, respectively.

3. RewriteRule - comes after one or more RewriteCond. This is a URI translation rule that only applies if a RewriteCond is executed.

The syntax for the RewriteRule directive is as follows:

RewriteRule Template Substitution

Here it is worth giving an explanation of the regular expression characters used, which defines string patterns:

Metacharacters are used to define groups of characters and labels in a template:

  • ^ - label of the beginning of the line,
  • $ - end-of-line mark,
  • \\ - escape slash, allows you to consider the following metacharacter as an ordinary character,
  • ... - dot, denotes any character, but only one,
  • () - grouping.
  • ! - negation,

Flags define additional options for this rule and are listed in square brackets, separated by commas:

  • NC - (nocase) disables case checking.
  • R - (redirect) stops the conversion process and returns the result to the client browser as a redirect to the given page (302, MOVED TEMPORARY). With this flag, you can specify a different result code, for example, R \u003d 301 will return a redirect with a 301 code (MOVED PERMANENTLY).
  • L - (last) stops the conversion process and the current link is considered final.

How to make a 301 redirect?

Now, knowing these rules, we can try to do it ourselvesredirect with htaccess.

  1. Redirect .htaccess to another page
Redirect 301 /old-post.html http://new-site.ru/new-post.html
  1. Redirect.htaccess from www to non-www
RewriteEngine on RewriteCond% (HTTP_HOST)! ^ Site.ru $ RewriteRule ^ (. *) $ Site.ru/$1
  1. Redirect.htaccess from non-www to www
RewriteEngine on RewriteCond% (HTTP_HOST)! ^ Www.site.ru $ RewriteRule ^ (. *) $ Www.site.ru/$1

where site.ru is your domain name.

  1. Redirect with index .php (html) to home page
RewriteEngine on RewriteCond% (THE_REQUEST) ^ (3.9) \\ / index \\. (Php | html | htm) \\ HTTP / RewriteRule ^ (. *) Index \\. (Php | html | htm) $ $ 1
  1. Redirect with a slash to without a slash
RewriteCond% (REQUEST_URI)! \\? RewriteCond% (REQUEST_URI)! \\ & RewriteCond% (REQUEST_URI)! \\ \u003d RewriteCond% (REQUEST_URI)! \\. RewriteCond% (REQUEST_URI)! [^ \\ /] $ RewriteRule ^ (. *) \\ / $ / $ 1
  1. Redirect from pages without slash to slash
RewriteCond% (REQUEST_URI)! \\? RewriteCond% (REQUEST_URI)! \\ & RewriteCond% (REQUEST_URI)! \\ \u003d RewriteCond% (REQUEST_URI)! \\. RewriteCond% (REQUEST_URI)! \\ / $ RewriteRule ^ (. * [^ \\ /]) $ / $ 1 /
  1. Redirect all pages of one domain to the main one of another domain
RewriteCond% (REQUEST_URI) (. *) RewriteRule ^ (. *) $ Http://site.ru/
  1. Redirect from http to https via. htaccess
RewriteCond% (HTTPS)! \u003d On RewriteRule ^ (. *) $ Https: //% (HTTP_HOST) / $ 1
  1. Redirect from https to http
RewriteCond% (HTTPS) \u003d on RewriteRule ^ (. *) $ Http: //% (HTTP_HOST) / $ 1
  1. Getting rid of duplicate pages

If you notice that something like & sa \u003d 123 456 or & crw \u003d 123 456 and the like is glued to the main page address, just replace the letter part in the following code

RewriteCond% (REQUEST_URI) ^ (. *) \\ & Sa \u003d RewriteRule ^ (. *) \\ & Sa \u003d (. *) $ $ 1

Example: explaining on the fingers

How to use a 301 redirect to make the site.ru/category/art1/zapis/ request in the address bar site.ru/zapis/, that is, / category / art1 would be cut from the line, but after the line was cut, the site content was shown .ru / category / art1 / zapis /?

RewriteCond% (ENV: REDIRECT_STATUS) ^ $ RewriteRule ^ category / art1 / zapis / $ http: //% (HTTP_HOST) / zapis / RewriteRule ^ zapis / $ / category / art1 / zapis / [L]

Now let's take a closer look at what is written here and what is happening in general.

As you know, mod_rewrit on apache constantly scans the list of rules while the URL can be somehow changed.
And not infrequently endless cycles are obtained.

To limit the loop of execution of rules to one iteration, you can use the construct from the first line. It gives apache the status of whether the redirect was executed or not, and if so, skip the following rules. By the way, this line is not needed on nginx.

The second line makes a 301 redirect from www.site.ru/category/art1/zapis/ to www.site.ru/zapis/
The third line tells the server that if the address is like www.site.ru/zapis/, then it is necessary to show what is located at www.site.ru/category/art1/zapis/

Remember that with the great power of redirection comes great responsibility, so use this knowledge wisely.

  1. Principle "from small to large": arrange redirects from private to more global. That is, redirects from page to page will be higher thanredirect from no www to www.
  2. Avoid sequential - double, triple - redirects. One redirect redirects the user only once.
  3. Check the HTTP headers and server response statuses to make sure the redirect is working properly.

In conclusion, I would like to announce the points under which it is worth and not to use.htaccess redirect.

When a redirect is needed

  1. You have moved to another domain: and you logically do not want to lose your clients - present and potential, and also there is a need to transfer the weight of the previous site to the new one.
  2. Want to glue mirrors: you have multiple domain names with different spellings of the brand and you redirect all visitors to the main site.
  3. Page has changed its address: Your site structure has been reorganized and you are trying to prevent a possible mess.
  4. Do you want to get rid of duplicate pages or copy of a site: do not treat duplicates as something harmless and insignificant. With duplicates, you lose weight and give up positions to competitors, as well as duplicate content can lead to fines from search engines.

When shouldn't you use a redirect?

  1. You are temporarily moving to a new page: there are codes 302 and 307 for this, this is a guarantee that the pages will not merge and the original page will not fall out of the search results.
  2. You are moving because of problems with the old domain: if you have bans, filters and fines, then when gluing, not only TIC and PR, but also all the troubles you fled from, will go to you.

A redirect, or redirect, is a way of moving users, as well as search engines, to web pages that have changed their location. There are several types of redirects, the main types of which are temporary and permanent.

301 is permanent and is used if the previously used address is completely out of date. A complete instruction on how to make a 301 redirect correctly will be useful for a novice webmaster, and even a fairly experienced specialist can find useful information in it.

DIY 301 redirect

301 redirects are usually used in such cases:

  • Domain change. Redirect allows you to make it invisible to users, ensuring that they move to a new address when they enter the old one into the address bar.
  • The need to keep search traffic, Page Rank and TIC, transferring them to a new domain.
  • Existence of multiple mirror sites with different URLs and the need to redirect traffic to the main domain when the user enters any URL.
  • Combining two sites and the need for links to outdated pages to work correctly.
  • Move the page to a new location.
  • The need to glue the site name.

How to set up 301 redirects - complete instructions, sample code

To make a decision as to which site to canonical - with or without "www", with or without a trailing slash, you need to analyze the position in the top and indexing of each option.

To merge a domain containing "www" with a domain without it, use the code:

RewriteCond% (HTTP_HOST) ^ www.site \\ .com $

RewriteRule ^ (. *) $ Http://site.com/$1

For the reverse procedure:

RewriteCond% (HTTP_HOST) ^ site \\ .com $

To remove a slash:

RewriteCond% (HTTP_HOST) (. *)

RewriteCond% (REQUEST_URI) / $

RewriteRule ^ (. *) (/) $ $ 1

To add it:

RewriteCond% (REQUEST_FILENAME)! -F

RewriteCond% (REQUEST_URI)! (. *) / $

RewriteRule ^ (. * [^ /]) $ $ 1 /

To redirect the page:

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

To redirect from duplicates of the main page to the canon version:

RewriteCond% (THE_REQUEST) ^ (3.9) \\ / ([^ /] + /) * (default | index | main) \\. (Html \u200b\u200b| php | htm) \\ HTTP /

RewriteRule ^ (([^ /] + /) *) (default | main | index) \\. (Html \u200b\u200b| php | htm) $ http://www.site.com/$1

For a directory redirect, the structure of which is inscribed in the URL:

RewriteRule ^ (. *) / Old-catalog /(.*)$ $ 1 / new-catalog / $ 2

To redirect a directory whose URL starts right after the domain:

RewriteRule old-catalog /(.*) / old-catalog / $ 1

For cases when only the URL extension is changed (site transfer to another platform or CMS):

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

How do I move to a new domain? The best option for a 301 redirect

Domain change is one of the most common reasons for performing permanent redirects. The question was how to move to a new domain? Developed taking into account the algorithms of the main search engines of the Runet, Google and Yandex, the best option for 301 redirects is carried out according to the following scheme:

  • permanent redirection of each page of the old site to the new one;
  • only the robots.txt file is not subject to redirection; instead, it contains the Host directive specifying the new domain.

On the old site, the following code for setting up a 301 redirect is prescribed:

RewriteCond% (REQUEST_FILENAME) robots.txt $

RewriteRule ^ ([^ /] +) $ 1 [L]

RewriteCond% (HTTP_HOST)! ^ Www \\ .site \\ .com

RewriteRule ^ (. *) $ Http://www.site.com/$1

The robots.txt file for the old site should look like this:

User-agent: Yandex

Disallow:

Host: newsite.com

How to set up the main site mirror

The search engine robot detects sites with full or partial content matching on pages with the same addresses as mirrors and glues them together, indexing only the main thing during search. The choice of the main mirror is carried out automatically according to the search engine algorithm or in accordance with the instructions of the webmaster. When changing a domain, it is often necessary to turn a new domain, which is temporarily a non-main mirror, into the main one, and the question arises of how to set up the main site mirror. Possible options:

  • the Host directive is applied, and the name of the main mirror is specified as its value. The choice of the main mirror as specified in this directive is not guaranteed, but the probability is high;
  • a server redirect is carried out from the pages of the old resource, which will now be a non-main mirror, to the new one.

To speed up the entry into force of changes, you need to select a site through Yandex.Webmaster, in the "Help" section, open the "Indexing settings" item and click on the "Main mirror" link. Here you can put a checkmark in front of the domain, which should be perceived by the robot as the main one during indexing.

How and when to use 301 redirects vs Canonical

While operations such as a permanent redirect (301) and specifying the main (canonical) URL using the Canonical attribute are quite similar, they are perceived differently by search engines. Therefore, depending on the situation and goals, you need to make the right choice of tool.

  • A 301 redirect is perceived by the search engine as an indication that the old address is outdated and will no longer be used, so the old page no longer needs to be indexed. It should be removed and its entire weight should be transferred to the page with the new address.
  • Canonical indicates that there are several versions of the page intended for people, and none of them should be deleted by the search engine. But only the main, canonical page will be indexed, and all weight should be transferred to it.

By default, a permanent redirect is preferred, but there are a few nuances and rules of how and when to use a 301 redirect vs Canonical.

A 301 redirect is applied if:

  • the address of an individual page has changed forever;
  • the site has finally moved to a new domain, the old one will no longer be used;
  • pages have been removed or their content is no longer relevant, redirects can be configured to pages with the closest possible content.

Canonical is preferred when:

  • a permanent redirect is not feasible or the procedure is time consuming;
  • there are some differences in the two duplicate content pages that require both versions to be available to users;
  • it is necessary, according to certain criteria, to distinguish pages with the same content and different URLs (track affiliate links, sort products in the catalog by different filters);
  • there are cross-domains with similar sites and similar content should be available on each.

How to make a 301 page redirect correctly

It is very important after the end of prescribing the forwarding codes check resource performance:

  • go to the main page to make sure that the site is working at all;
  • check the loading of the main sections, the most important pages;
  • use the services http://bertal.ru and http://www.internetmarketingninjas.com/header-checker/ for testing.

If you have insufficient skills, it is better not to perform 301 redirects with your own hands, but to use services that allow you to generate codes for the main cases of redirects, substituting your own data into the template. Examples of such services:

Errors in use

Not everyone knows how to set up a 301 redirect correctly. The most common mistakes when using permanent redirects:

  • multistep redirect is performed - works slowly, loss of link weight is possible;
  • the wrong type of call forwarding is selected, which does not match the purpose;
  • an internal redirect is being implemented on the site, but the link addresses do not change to new ones;
  • redirects are made to pages that are not relevant enough to the original;
  • the wrong choice was made between redirect and Canonical;
  • the redirect does not lead to a correctly working (with a 200 response) page;
  • the robots.txt file is redirected instead of specifying the Host directive in it.

Hello my dear friends! Today I decided to write an article about the "scary" concept as 301 redirect ... Yes, do not be alarmed, in fact, everything is very, very simple :). In this article I will tell you what it is, why you need it, how to make it, and a lot of other equally useful information on this topic!

News number 1

I got very into investing in various popular brokerage companies. I've already written a couple of articles on this topic, where I invested a little money:

  1. Article about;
  2. An article about investing in.

In these articles I told where and how much I invested. You will soon find out about another equally profitable brokerage company, so do not miss this article! Monthly income from investing in this company, or rather in this trust management program, is from 7-40%.

Now, let's see what a redirect is.

Redirect Is a transfer (redirection or redirection) from one domain name to another (from one site to another), from one page of the site to another. Those. the user types one page or site name in the line of his browser, and ends up on a completely different page or site name.

Why do webmasters need 301 redirects?

Use a 301 redirect in the following cases:

1. For gluing .

Remember, in the last article I talked about the undesirability of having a website with the www domain, as this leads to a redistribution of the link mass into two domains and, as a result, negatively affects the ranking of the site in search engines;

2. When the site moves to a new domain. It so happens that a site falls under various search engine filters, search traffic decreases (or disappears altogether), so there is a need for a new domain. What about regular blog readers? What about those who have bookmarked or subscribed to your blog? This is where 301 redirects come in handy;

3. To increase the TCI and PR of the site, to maintain search traffic. For example, you want to increase the PR for a certain site (main). To do this, you need to buy with already existing good puzomers and make a redirect to the main site, then the TCI, PR and search traffic will be transmitted to it.

4. If you need to change the page address. For example, if your page is ranked high in search engines or has been indexed and you don't want it to fall out of the index, then a 301 redirect is just what you need.

5. When switching from free hosting to paid.

There are also a number of other uses for the 301 redirect, but for now let's dwell on the above.

Redirect classification

As I said, for general development, a novice webmaster needs to know that in addition to 301 redirects, there are others:

But most often they use 301 redirects.

How do I do a 301 redirect via .htaccess file?

The question arises: what is a file .htaccess ? This is the file that will store various 301 redirect commands (about page redirects, domain redirects, etc.).

The fact is that you cannot rename it in the usual way on a computer, an error is generated (for me), but with the help of the above programs, you can definitely.

And now we open the file (using a text editor) and enter the required redirect code.

If you want to redirect visitors from one site to another

Redirect 301 / http: //www.domain.com

Redirect 301 - indicates that the site has been moved;

"/" - indicates that everything from the top level of the blog will be moved (redirected) to the new domain.

For example, if you want to redirect from one page of the site to another page of the site, then in the .htaccess file you need to insert the following code:

Redirect 301 / old-page.html http: //new-domain.com/new-page.html
or
Redirect permanent / old-page.html http: //new-domain.com/new-page.html

RedirectPermanent / old-page.html http://new-domain.com/new-page.html

Redirect using the RedirectMatch directive

This redirect is almost the same as the previous one, but here you can set a regular expression for the old ones, for example, when changing CMS from PHP to ASP, the redirect code will look like this:

RedirectMatch /(.*)\\.php$ /$1.aspx

Redirect 301 from a domain from www to a domain without www

RewriteEngine on
RewriteCond% (HTTP_HOST) ^ www.site.ru $
RewriteRule ^ (. *) $ Http://site.ru/$1

Redirect 301 from a domain without www to a domain with www

RewriteEngine On
RewriteCond% (HTTP_HOST) ^ site \\ .ru $
RewriteRule (. *) Http://www.site.ru/$1

RewriteEngine on | off - this is a special directive that serves to disable or enable access to the code of the .htaccess file, access is performed through the mod_rewrite hosting module;

RewriteCond - it is a special directive that defines conditions for transformation rules. It is a directive of the mod_rewrite hosting module;

RewriteRule - it is a directive that is responsible for various transformations. In this case, a 301 redirect.

First, information about the page goes to the RewriteCond directive, after which this information is converted to the RewriteRule directive. This is how the above code works, in short.

Yes, the information is difficult to understand (at first), but if you master it, then it will be much easier in the future.

And on this I will finish the article, bye everyone!

P.S.

Best regards, Alexander Sergienko

Hello dear friends and guests of the blog site! Now you will learn how to do a 301 htaccess redirect correctly on a website and, in general, what a redirect is and why is it needed on a resource? Go …

301 redirect - this is a resource status code that appears on it when redirecting to another site and is sent to the client, i.e. browser.

What is it for? In general, redirecting a user from one page address of a site to another is necessary when moving a site to a new address or when changing the address of a post on the site and in various similar situations arising from some circumstances.

for instance when switching a site from http to https... I wrote about this earlier! Just to translate the site to https, you need to write a redirect code in the htaccess file, which will indicate to search engines that your site is now located at an address starting with HTTPS. Here's the code:

  • RewriteCond% (SERVER_PORT)! ^ 443 $
    RewriteRule ^ (. *) $ Https://site.ru/$1

or like this:

  • RewriteCond% (HTTPS) \u003d on
    RewriteRule ^ (. *) $ Http: //% (HTTP_HOST) / $ 1

Actually, there are a lot of types of redirects, here are some of them that are considered the most important and in demand among webmasters ...

Types of 301 redirects for a webmaster!

301 redirect from www to non-www (main mirror - domain without www)

RewriteCond% (HTTP_HOST) ^ www \\. (. *) $
RewriteRule ^ (. *) $ Http: //% 1 / $ 1

301 redirect from without www to www (main mirror - domain with www)

RewriteCond% (HTTP_HOST) ^ ([^ www]. *) $
RewriteRule ^ (. *) $ Http: //www.%1/$1

301 redirects from one page of the site to another

RewriteCond% (REQUEST_URI) ^ / test / $
RewriteRule ^. * $ Http://site.ru/new-test/?

Important!

To fix an error on the site (the appearance of duplicates of the main page!), You need to install the following code in the htaccess file of your site:

RewriteCond% (THE_REQUEST) ^ (3.9) \\ / ([^ /] + /) * (default | index | main) \\. (Html \u200b\u200b| php | htm) \\ HTTP /
RewriteRule ^ (([^ /] + /) *) (default | main | index) \\. (Html \u200b\u200b| php | htm) $ http://www.site.com/$1

Then the home page of your site will not be available at several addresses, for example: home.php, index.php, default.php, etc. Accordingly, the ill-fated duplicates of your home page will disappear and the site will rise in the search results due to the disappearance of this error.

Here's another useful service to help you create anonymous redirect links for your site: Katvin.com

That's actually all that I wanted to tell you today. Thank you for your attention! Until next time!