If there is a need to move the site to another domain in order to save traffic and not only webmasters and web developers often use 301 redirect with which the user is automatically redirected so to speak from the inactive url to the active, that is, working. Redirect is also used for gluing a domain with or without www. In this article we will look at how to do a 301 redirect on your website.
There are several ways to solve the above task. The easiest is to add to the file .htaccess, which is located on the server of the following line:
Redirect 301 / http://www.site.com/index.html
In this case, Internet users from all pages of the old site will be redirected to the new domain.
If you want to redirect users from only one specific page to another .htaccess add this rule:
Redirect 301 /site1.com/post1.html http://site2.com/post2.html
The same can be done using php, here’s an example:
header(“HTTP/1.1 301 Moved Permanently”)”);
header (“Location: http://www.site.com/index.html”);
This code snippet should be placed in the php script itself, at its beginning.
So summing up, I want to emphasize once again that automatic redirection on the site is useful in three cases: when moving the site to a new domain; when pasted domain and when redirecting the user to a separate page. But it should be remembered that when transferring the site to a new domain only one redirect to save the positions of the site in the search results and pages in the index should not be limited. A number of other special events are required for this purpose.