/ / How to set up 301 redirect via .htaccess. The right attitude as a 301 redirect in Joomla and other CMS

How to set up a 301 redirect via .htaccess. The right attitude as a 301 redirect in Joomla and other CMS

About 301 redirect, many have heard more than once.But because of the lack of need for it, and also because of the fear of doing something wrong, they did not attach great importance to such a procedure. The article will discuss in detail how to configure the 301 redirect.

Про его настройку можно найти не один десяток articles and information materials. But after seeing many of them, novice computer users and webmasters may have difficulty understanding the basics of customization. Numerous codes and scripts provided in online sources of information, for the most part cause confusion. In fact, everything is much simpler, and this article will serve as a good guide on how to configure the 301 redirect.

What is 301 redirection?

Understand everything in order.First of all, we give the definition of a 301 redirect. By it we mean the simplest redirection of a guest 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 tricky scripts and too complex code, but will show some simple redirection options that are sufficient basic knowledge of this topic for any webmaster.

Tool for 301 redirect - .htaccess file

Consider a handy tool like.htaccess. Redirect 301 through it is very convenient and simple to do. Htaccess is inherently a special service file in the configuration, which contains a lot of 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, perform 301 redirects and some other actions.

how to set up redirect 301

This is a description of the capabilities of this file in general terms. 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 file .htaccess

If the root folder of the site is missingfile, it can be very easy to create on your own. One of the fastest ways to create is to use an FTP client. The most convenient of them is FileZilla.

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

htaccess redirect 301

But it also happens when FTP clients hidesome system files, including .htaccess. Therefore, if this file was not found in the root folder, do not rush to create it. First of all, check its presence in hidden files. To do this, go to the “Server” tab and set a tick on the forced display of hidden files.

So, the .htaccess file has been created or found, the 301 redirect using it will be easy to create. However, first of all, you need to decide what it is for.

The most popular case when 301 redirect can come in handy

According to the recommendations of leading webmasters, eachresource on the web must have a 301 redirect. And the most popular case, when it is very necessary, is redirection from the domain, which in its composition has a prefix from www to the domain without it and vice versa.

This is because of any site on the net.The Internet is only one type of domain name with www or without it can be the main. Another option will be a mirror of the site. The main mirror of an Internet resource is signed in the robots.txt file using the Host directive. In addition to this file, the main version of the domain should be specified in Yandex.Webmaster. Many search engines treat a tool like 301 redirects well. Yandex is not an exception.

how to set up 301 redirects

При указании главного зеркала интернет-ресурса Your site will be indexed correctly and will not create unnecessary duplicates. Many newbie webmasters have never heard of site mirrors, which is a very big mistake that will cause major troubles in the future.

The value of setting site mirrors

After all the actions done with the mirrorSearch engines will determine the main domain automatically. You can even easily check the redirect, everything will work fine. It would be possible to stop on these actions, but the best way for SEO-optimization of an Internet resource will be the additional setting of the redirect.

Сам префикс www в обозначении уже давным-давно had to go into oblivion. Nevertheless, there are still many resources on the Internet with www in the title. For search engines, domains with and without www are two different addresses. Yes, and many users when searching for a specific Internet project are driving into the address bar the option with www. Therefore, this prefix is ​​still there to be. Based on this fact, tuning mirrors is a necessary action. And the guide on how to set up a 301 redirect is also a must-read in order for your Internet project to be successfully indexed in search engines.

The consequences of improperly setting the mirrors

In order to appreciate the full significance of 301redirect and correct setting of the mirrors, we highlight the detrimental consequences of their incorrect operation. There are not so many, only two. But the weight of each item is very high.

Внешние ссылки будут разделяться между доменами с www and without it in direct proportion to how other users and sites will link to your resource. This suggests that your Internet project will lose some links, which will adversely affect its attendance and place in the search results. However, this is not the main problem.

how to set up 301 redirects to www without www

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

You know nothing about it and further developyour 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 the ban for non-unique content. Over time, it will completely cease to be indexed.

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

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

How to set up a redirect in this case. Everything is simple. You need to open the .htaccess file and put the following script into it.

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

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

And in a different way:

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

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

redirect 301 what is it

Следует сохранить файл .htaccess and transfer it to the root folder, followed by replacing the last file. Now, the visitor will be redirected to the main page in all cases if any site address is entered (even from http, even without it, even with www, even without it). We looked at how to set up 301 redirects to www without www. Let's now deal with the other ways to use it.

Transition from one Internet project domain to another

A similar redirection scheme that is givenabove, should be used when switching from one domain of an Internet project to another. For demonstration we give an example. Let's say you should move from the moysait-1.com domain 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].

CNC link change and redirect while

Временами возникает необходимость сменить ссылки CNC. It is quite possible that such a situation developed that it was decided to change the entire section on its resource. Or the site owner did not know anything about the CNC links, and the blog already existed and was filled with materials. In this case, redirection can help. How to set up 301 redirects for such a case? It is important that in this situation, all indicators of the pages (links, their weight in search results) will remain the same.

redirect 301 php

Приведём простой пример.It was decided to change the name of the page 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.moydomen.com/obo_mne.html.

The redirect 301 from page to page is produced in a similar way.

Redirection when changing the file extension

We give one more example.The webmaster needs to change the extension of the file moya_stranichka.html to moya_stranichka.php. Like the last paragraph, we write the following code in .htaccess: redirect 301 moya_stranichka.html http://www.mydomain.com/moya_stranichka.php.

Redirects for affiliate programs

For example, you must redirect a visitor.site on page with affiliate program. The link of the affiliate program itself looks like www.partner.com/?ref=16011. Noticing such a link, many visitors to the resource will not click on it, having guessed about your intentions beforehand.

To give the link a proper look, you needcreate a separate page, as an example dlya_druzei.html, which will be redirected to a page with an 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 look at how to redirect 301 in the Joomla engine and using the PHP language.

How to redirect 301 in CMS Joomla

Many Internet users for sureobserved a page with an error 404. In the Joomla engine there are already several built-in ways to redirect from page to page. However, they do not always work. And they are very difficult for an ordinary user to understand. Here the redirect 301 comes to the rescue. Joomla has in its standard composition a .htaccess file, with which you can perform all the manipulations described above.

redirect 301 joomla

Let's configure for redirectsacross 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, in the redirection settings, enable NC (SEF) and tick the redirection URL.

Then you should open the .htaccess file and write the rules for the necessary redirects in it.

Redirect with PHP

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

To redirect withdomain to domain with all parameters saved, you need to create a file with the .php extension in any text editor, call it index and copy the following script there:

if ($ ref! = "") $ ref = "?". $ ref; header ("HTTP / 1.1 301 Moved Permanently");

header ("Location: http://moydomain.ru/".$ref);

exit ();

?>.

Here moydomain.ru is the domain to which the redirect is performed. The resulting file must be uploaded to the server in the main directory of the site.
In order to make a redirect from page to 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.moydomain.ru/moycategory/moypage.htm");

exit ();

?>.

As a result, www.moydomain.ru/moycategory/moypage.htm is a new page that is redirected to.

It is important to take into account that the page into 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 use a redirect through .htaccess.

Now, after studying the article, any webmasterwill know how to set up a 301 redirect, what it is and how it is useful. Here are the most simple options for using redirects. However, they need to have an idea of ​​any site owners and blogs. And it is worth taking into account that it is important not only to set up the correct redirection, but also to check it for proper operation.

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

Liked:
0
Popular Posts
Spiritual development
Food
yup