When working on the optimization and promotion of sites sometimes there is a need to remove from the indexing of irrelevant, non-existent or unnecessary pages. This is done by means of 301 redirects.
Also, when working on SEO-audit we have a point “Site mirrors,” there we check all the mirrors on the response of the server, and if all but the main mirror gives the answer “200”, then we recommend setting 301 redirect from non-main mirrors to the main one. But our clients often have a question, what kind of a redirect is this, 301. Well, the answer is.
A redirect is a redirection of a user from one url address to another.
To put it simply: it happens that a user types one page address, but ends up at a completely different one. This can be related to the fact that the data on the previous url has become irrelevant, while the new page contains related relevant information. Or the link became broken and 301 redirects were used to prevent the user from getting to this broken link.
301 and Other Redirects
There are 3 most commonly used redirects: 301, 302 and 303. And here’s what they mean.
- The 301 is the main subject of the article. It shows that the resource is moved to a new address permanently. Attendance figures are transferred to the acceptor site and the donor site disappears from search.
- The 302 is a temporary redirect that gives the status “found” (302 Found). Search bot understands the page as temporarily nonexistent (for example, during maintenance work) and redirects (redirects) the user to the right one. 302 does not transfer link weight to the acceptor. For search engines this is seen as duplication of pages, and often the old page is excluded from the extradition.
- 303 (See Other) – This redirect is similar to the 302 and also means a temporary redirect.
We are primarily interested in redirecting from one to another site permanently, that is, the first option.
Now let’s understand what 301 redirect is for and how to use it.
What 301 Redirects are Needed For
- When linking resource mirrors. Without configured 301 redirect any site will be available for indexing by robot all the mirrors, such as https://, http://, https://www and http://www. This should not happen, because the robot thinks that all sites are different, and each mirror crawls separately. This can lead to an incorrect distribution of link mass to different mirrors and adversely affect the promotion of the resource.
- When transferring the site to another domain. Sometimes it is necessary to move to another domain for different needs. Whether it is a sharp decline in traffic, or rebranding the company with a smooth migration of content. But the fact remains that the old domain will soon be unavailable. To avoid the loss of regular visitors or those who have the site bookmarked, you need to set up a 301 redirect. So when a user clicks on the old domain, he will be moved to the current one.
- For mobile. For fast transition from tablets and mobile devices to the adapted version of the site is also used 301 redirect.
- When moving to another hosting site with a change of address.
- When deleting a pre-existing page. To prevent users from seeing a 404 page, you can make 301 redirects either to the home page or to a page with similar content.
- In the case of duplicates. Pages with similar content impairs the ranking, and if the pages completely repeat the content of each other, the search robots may even exclude the page from search. Therefore, to eliminate the risks, it is recommended to set up 301 redirects.
301 Redirect or rel=”canonical”?
The point about duplicates may raise a question: why use 301 redirect when you can use rel=”canonical” attribute?
Let’s figure it out.
- 301 redirect is necessary when the page permanently moved to another location and it will not be available at the old address. And with redirect we remove it from the index and pass the weight to the new page.
- Canonical is needed when there are several pages with very similar content, and we use this attribute to determine the canonical page, which should crawl the search bot. The remaining pages will remain available to visitors, but will not be indexed.
In other words, while seemingly similar, these are completely different methods. By redirecting, we let both the user and the search bot know that the old page no longer exists and that we should focus all of our attention on the new, relevant page or site, even if the content is different.
By using canonical with two pages with similar content, we give the search bot a command to index only the page that is preferred to be given weight. Content on non-canonical pages remains visible to visitors.
A properly configured 301 redirect will at least help to avoid possible failure on the site, because if a visitor comes to an old page or resource with an unconfigured redirect, he will simply see a 404 error or a completely non-working site and will look for what they need on other sites.
301 redirect is configured in different ways and below we will discuss them.
Common Types of 301 Redirect
Let’s see what types of 301 redirects exist, what they are for and how to use them.
Htaccess Redirect
The method for the Apache web server.
.htaccess is a system file that should be in the root of the site. If it does not exist, it should be created using Notepad++ in Windows.
To gain access to it, go to the control panel hosting, which is the desired site. Or if you have access to FTP, you can find the file through this protocol.
If the file already exists, don’t forget to back it up!
So, setting up a 301 redirect through .htaccess goes for:
Domain Transfer
To configure a redirect for domain transfer through this type, you need to open a .htaccess file and find the following lines in the file:
RewriteEngine On RewriteBase /
If they are not present, they should be added at the end of the file. Immediately after the entry, insert the following code:
RewriteCond %{HTTP_HOST} ^old-site.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
Where
- old-site.ru – the domain from which we set up the redirect;
- new-site.ru – the domain to which we set up the redirect.
Moving from http to https
To configure the domain move from http to https via 301 redirect all steps are almost similar to the above.
Also we are looking for lines
RewriteEngine On RewriteBase /.
Or add them to the end of file, if they are not present. After them write the following code:
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
where https://domain.com – is your site.
Generally, it’s 2022, and if the site is on https, it’s a good tone for both users and site administrators.
This protocol is much safer than http, and entering the site with a secure connection, the user can be calm that his data can not be stolen by intruders, and especially brazen mobile operators can not embed ad units directly in the site.
Gluing With and Without the WWW Prefix
To glue the site with the www prefix and without the www, the actions are similar.
Look for or add lines
RewriteEngine On
RewriteBase /
After them insert code:
RewriteCond %{HTTP_HOST} ^www.(.*)$
RewriteRule ^(.*)$ https://site.com [L,R=301]
where site.ru is the acceptor page.
Redirect for internal pages
Setting up a 301 redirect among internal pages is much easier. There is no need to write several lines of code with rules. To configure redirect on internal pages use following code in .htaccess file:
Redirect 301 /page-old/ https://site.com/page-new/
Symbols Used in Redirects
\ – escaping slash that preserves the characters that come after it in their original form
^ – start of line
$ – end of line
! – negation character
. – any character
# – comments
( ) – character grouping symbol
PHP Redirect
To configure it this way you need to open (before downloading to your PC) index.php and write the following code in the beginning:
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: https://www.newdomain.com/”);
exit();
?>
Next we need to save the changes and upload the file to the server.
This redirection was done by sending headers.
JavaScript Redirect
This type of redirect is the slowest, because redirect is performed on the side of the browser, not the server. But with its help you can warn users about the change of the page address. For example, when entering a page with a redirect, a text “Page has moved, now you will be redirected there” will be displayed, and in a few seconds the user will be moved there.
To set up this redirect type, you need to add code between the <head> and </head> tags of the page you are redirecting users from.
This code must be inserted inside <head>:
<script>
SetTimeot(‘location.href = ‘/’;’,2000);
</script>
That’s how we set up a redirect with a 2 second delay.
HTML Redirect
Like the last type of redirect, this also works on the browser side, so the speed of redirection will not shine.
To add a redirect on the page from which it will be performed, add the following code between the <head> and </head> tags:
<meta http-equiv=”refresh” content=”3 url=/”>
Save the changes and check them.
NGINX Redirect
For the Nginx web server 301 redirect from one page to another is configured in the configuration file (or via htaccess), like this: server {listen 443;location /cat/first {return 301 /second/;}
Web.config Redirect
This method is for IIS servers. The redirect is configured in the XML file web.config. There are also all the basic settings of the server. Redirect from one page to another:
<configuration> <location path=”page1.htm”> <system.webServer> <httpsRedirect enabled=”true” destination=”https://site.com/page1″ httpsResponseStatus=”Permanent” /> </system. webServer> </location> <location path=”page2.htm”> <system.webServer> <httpsRedirect enabled=”true” destination=”https://site.com/page2″ httpsResponseStatus=”Permanent” /> </system.webServer> </location></configuration>
Services to Generate a Redirect
If you do not want to write all the rules for the redirect manually, there are several services that will do this for you. You need to enter the address of the old page and the new page into the appropriate fields, and the service will generate code, which, for example, will need to be inserted into the .htaccess.
Seomagnifier
With this service you can create 301 redirect code from www to domain without it and vice versa.
301 Redirect Code Generator
Allows you to generate code for all of the above redirect types.
Redirect generator
Another 301 redirect generator with user-friendly interface.
Simple Htaccess Redirects & Rewrite Generator
Universal redirect generator. With it you can set up the main url, both with a slash at the end of the address “/” and without it.
In almost all of the generated variants in the code can be comments of the service itself – feel free to erase them.
Services for Redirect Validation
To quickly check the result of his work, there are several services (so-called checkers), which will show the type of redirect, as well as the response of the server.
PrCy checker
Shows if there is a redirect on the site.
Redirect checker
English-language redirect checker. Shows redirect type and server reply status.
Bottom Line
In general, it is not too difficult to “tweak” the structure of the site: it is important to follow the sequence of rules, and then 301 redirect will work correctly. Hide unnecessary pages for viewing, above all, so you save time for the site visitor to find the necessary information.
And if you want to save your time, we are happy to help you! Translate your site to https, set up 301 redirect, as well as perform other work to improve the site.
