ComputersSecurity

How to configure the redirect 301 through .htaccess. The correct attitude as a 301 redirect in Joomla and other CMS

Many people have heard about the redirect many times. But due to lack of need for it, and also because of fear of doing something wrong, did not attach importance to such a procedure. The article will discuss in detail how to set up a redirect 301.

About its configuration, you can find more than a dozen articles and information materials. But after viewing many of them, beginning computer users and webmasters may have difficulty understanding the basics of the setting. Numerous codes and scripts provided in online sources of information, for the most part cause misunderstanding. In reality, everything is much simpler, and this article will serve as a good guide to how to set up a redirect 301.

What is 301 redirect?

We'll figure it out in order. First of all, let's define redirect 301. It is understood as the simplest redirection of a guest of a resource on the Internet (site) to another page on the network or a domain name. Immediately make a reservation that this article will not consider any cunning scripts and too complex code, but will show a few simple redirection options, which are sufficient basic knowledge on this topic for any webmaster.

The tool for 301 redirects is a .htaccess file

Consider such a handy tool as .htaccess. Redirect 301 through it is very convenient and easy. Htaccess is inherently a special service file in a configuration that has a very large functionality and many features. With it you can set a ban on access to any directories on the site server, specify the encoding of pages, set protection for folders and files, make 301 redirects and some other actions.

This is a description of the features of this file in general. In fact, its functionality is even more advanced. The file has no name and is written as .htaccess. The point at the very beginning is mandatory.

The procedure for creating the .htaccess file

If there is no file in the root folder of the site, you can create it yourself very easily. One of the fastest ways to create is using an FTP client. The most convenient of them is FileZilla.

To create, you need to go to the root directory of your Internet project - click the right mouse button of the computer mouse - select "Create new file" - enter the name .htaccess - click OK. After these actions, the created file can be edited. Its opening can be made by any text editor.

But it also happens when FTP clients hide some system files, including .htaccess. Therefore, if this file was not found in the root folder, you do not need to hurry to create it. First of all, check its presence in the hidden files. To do this, go to the "Server" tab and set a check mark for the forced display of hidden files.

So, either the .htaccess file was created or the 301 redirect using it will be created easily. However, first of all, it is necessary to determine what it is needed for.

The most popular case, when 301 redirects may come in handy

According to the recommendations of the leading webmasters, each resource on the Web should have 301 redirects. And the most popular case, when it is very necessary, is redirection from a domain that includes a prefix from www, to a domain without it, and vice versa.

This is because any site on the Internet only one type of domain name with or without www can be the main one. Another option is to mirror the site. The main mirror of the Internet resource is signed in the robots.txt file with the help of the Host directive. In addition to this file, the main variant of the domain should be specified in "Yandex.Webmaster". Many search engines are well related to such tools as 301 redirects. "Yandex" is not this exception.

When specifying the main mirror of an Internet resource, your site will be indexed correctly and will not create unnecessary duplicates. Many new webmasters never heard about mirror sites, which is a very big mistake, which will cause further trouble in the future.

The value of setting up site mirrors

After all the actions done with the mirror, the search engines will automatically determine the master domain. You can even easily check the redirect, everything will work well. These actions could be stopped, but the best way for SEO-optimization of the Internet resource will be additional adjustment of the redirect.

The very prefix www in the designation has long ago had to go into oblivion. But nevertheless in the Internet there are still a lot of resources with www in the name. For search engines domains with and without www - two different addresses. And many users when searching for a particular Internet project drive into the address line option with www. Therefore, this prefix is still in place. Based on this fact, setting up mirrors is a necessary action. And the guide, how to set up a redirect 301, is also mandatory for learning, so that your Internet project is successfully indexed in the search engines.

The consequences of improper mirror settings

In order to assess the importance of 301 redirects and the correct adjustment of mirrors, we will highlight the harmful consequences of their incorrect work. There are not so many, only two. But the weight of each item is very high.

External links will be divided between domains with and without www, depending on how other users and sites refer to your resource. This indicates that your Internet project will lose some of the links, which will negatively affect its attendance and location in the search results. However, this is not the main problem.

Many webmasters understand that search engines are constantly fighting for the uniqueness of the content of Internet resources. They are very negative about the duplication of information and quite seriously punish sites with similar content, up to their complete blockage in the search results. Now let's outline the following situation: your resource was indexed from the very beginning with the www prefix, but over time, a domain without www received a larger number of visits and popularity (more often referred to and more often mentioned).

You do not know anything about this and further develop your project. Over time, it is filled with unique content, many links and comments. Search engines, while monitoring the resource without the www prefix, sent it to ban for non-unique content. Over time, it completely stops indexing.

In order to avoid this situation, there is a .htaccess file. Redirect 301, registered in it, is able to solve the problem of sharing a resource on domains with www and with its absence.

Redirection from the www domain to the site name without a prefix and vice versa

How to configure the redirect in this case. It's all simple. It is necessary to open the .htaccess file and assign the script below to it.

Redirection from the www domain to the site name without it:

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

And in another way:

RewriteEngine On
RewriteCond% {HTTP_HOST} ^ moydomen.com
RewriteRule (. *) Http://www.mydomain.com/$1 [R = 301, L].

It is necessary to take into account that instead of moydomen.com it is necessary to specify the address of your Internet resource in both cases!

You should save the .htaccess file and move it to the root folder, and then replace the previous file. Now the visitor at any driving in the address of the site (at least with http, even without it, even with www, even without it), will in all cases be redirected to the main page. We looked at how to set up a 301 redirect on www with no www. Let's now deal with the other ways of using it.

Going from one domain of an Internet project to another

A similar redirection scheme, as mentioned above, should be used when moving from one domain of the Internet project to another. For a demonstration, we give an example. Let's say you need to move from moysait-1.com to moysait-2.com. In this case, you should write the code in the .htaccess file:

RewriteEngine On
RewriteCond% {HTTP_HOST} moysait-1.com
RewriteRule (. *) Http://moysait-2.com/$1 [R = 301, L].

Changing CNC references and redirecting in this case

At times, you need to change the CNC references. It is possible, there was such a situation that it was decided to change the entire section on its own resource. Or the site owner did not know anything about CNC links, and the blog already existed and was filled with materials. In this case, redirection can help. How to configure 301 redirects for this case? It is important that with this state of affairs, all the indicators of the pages (links, their weight in search results) will remain the same.

Let's give a simple example. It was decided to change the page name from moya_infa.html to obo_mne.html. In this case, you need to write in the .htaccess code: redirect 301 moya_infa.html http://www.mydomain.com/obo_mne.html.

Similarly, redirect 301 is made from page to page.

Redirecting when changing file extensions

Let us give one more example. Webmasters need to change the extension from the file moya_stranichka.html to moya_stranichka.php. Like the past point, we assign the following code to .htaccess: redirect 301 moya_stranichka.html http://www.moydomen.com/moya_stranichka.php.

Redirect with affiliate programs

For example, you need to redirect a visitor to a site with a partner. The very link of the affiliate program looks like www.partner.com/?ref=16011. Noticing such a link, many visitors to the resource will not go over it, guessing in advance about your intentions.

To give a link of the proper kind, you need to create a separate page, as an example of dlya_druzei.html, with which you will redirect to the page with the affiliate program. It remains only to edit the .htaccess file: redirect 301 dlya_druzei.html http://www.partner.com/?ref=16011.

Further in the article we will consider how to make a 301 redirect in the Joomla engine and using the PHP language.

How to redirect 301 to CMS Joomla

Many Internet users have probably seen the page with a 404 error. The Joomla engine already has several built-in redirection methods from page to page. However, they do not always work. And are very difficult to understand by an ordinary user. Here the redirect 301 comes to the rescue. Joomla has in its standard composition a .htaccess file, with which it is possible to perform all the manipulations described above.

Let's configure for redirects to all pages of your Internet project. First of all, in the directory you need to find the file htaccess.txt and give it the correct name .htaccess. After that, in the admin panel, set the CNC enablement (SEF) in the redirect settings and check the URL redirection.

Then open the .htaccess file and assign the rules for the necessary redirections in it.

Redirect with PHP

If, for any reason, access to the .htaccess file does not exist or is closed, there is a way to do a different redirect 301. PHP will help in this.

In order to redirect from domain to domain with saving all parameters, you need to create a file with the extension .php in any text editor, name its index and copy the following script to it:

If ($ ref! = '') $ Ref = '?'. $ Ref; header ('HTTP / 1.1 301 Moved Permanently');

Header ('Location: http://mydomain.ru/'.$ref);

Exit ();

?>.

Here moydomain.ru is the domain to which the redirection is made. The received file should be uploaded to the server in the main catalog of the site.
In order to redirect from a page to a page within the same domain or different, you need to insert the following before the main code of the portable page:

Header ("HTTP / 1.1 301 Moved Permanently");

Header ("Location: http://www.mydomain.ru/mycategory/mypage.htm");

Exit ();

?>.

As a result, www.mydomain.ru/mycategory/moypage.htm is the new page to which redirection is carried out.

It is important to take into account that the page, in the code of which the above script is inserted, should have the extension .php at the end of the name. Otherwise, you will have to redirect through .htaccess.

Now, after studying the article, any webmaster will know how to set up a 301 redirect, what it is and how useful it is. Here are the simplest options for using redirects. However, they need to be known to any website owner and blogger. And it is worth considering that it is important not only to set up correct redirection, but also to check it for correct operation.

As you can see, redirects can be created not only with the help of the .htaccess file, but also through the standard features of many CMS, and with PHP scripts.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.