301-redirect: setup guide
What kind of beast is this redirect? A redirect is used to redirect a person or a SS bot to a different address that differs from the one initially requested.
Example: https://en.uaateam.agency/ is redirected to https://uaateam.digital/
WHEN 301 REDIRECT IS USED
The most common example of using 301 redirect in SEO promotion is linking site URLs. In this case, in addition to transmitting 90% of the link weight, the authority of the site being redirected from is also transmitted.
A redirect is also used for redirecting from one page to another if the page address needs to be changed for some reason, but you don’t want to lose the position of this address in the search results (of course, this is easier than promoting it again).
If you are moving to a new domain, it would also be good to redirect to it from the old one, because this way you can save traffic (people go to the old domain via bookmarks or enter an URL in the search, and in these cases they are redirected to the new domain)
You can also use a redirect to redirect a user from a broken link (a broken link is a link that the server sends the server’s 404 code when clicking on it) to some other one; or when you have pages with duplicate content on them.
But in such cases, there is also another option for correcting the error — deleting the page.
TYPES OF REDIRECTS
301 redirect is a permanent redirect that can be used to transmit more than 90% of the link weight. It also indicates that the page has a new address, and the old URL should be considered outdated.
302 and 307 redirects
The 302 redirect is temporary and transmits as much as 0% of the link weight and is not recommended for use. Its descendant in the HTTP 1.1 protocol is the 307 redirect. These types of redirects should only be used to move content temporarily, such as in case of maintenance works.
Other types of redirects
WHAT IS THE DIFFERENCE BETWEEN CONSTANT REDIRECTION AND 302?
In short, in case of 301 redirect, the search engine is given a signal not to go to the old address anymore, and the publication located on this page is no longer displayed in the search results.
With a 302 redirect, both pages will be indexed, which is why I repeat that it is better to use them only on a short-term basis.
TIPS FOR USING A REDIRECT
- Redirection should not be cyclical. If the page refers to itself, this may lead to the fact that when the site is indexed by a search bot, it is likely to fall into such a “loop”, which will eventually lead to the merging of the crowding budget and as a result, the site will not be indexed.
- You should not do a redirect from an address which is also a redirect, I mean, if you have page 1, 2, and 3, you do not need to do a redirect from first to second and from second to third place from first to third. This way the load on the server will not increase, and the redirect efficiency will not decrease.
- Placement rules of redirects should start with the general ones, and only after them to enter private ones, as in any conflict the first will be triggered to the general rule, and only thereafter to the private one.
- A useful redirect will be the one that leads to a page that copies the requested page in all its nuances.
WHERE ARE REDIRECTS SET UP?
The most popular and common method of performing redirects is to create a file called .htaccess in the site folder or edit it, if you have one.
When using the Apache web server, the file is called httpd.conf.
I recommend that you Backup the file or the entire site before making any changes.
Before going to the examples, I want to say that regular expressions are used to write redirect rules. In addition to the redirects, they can be used in Analytics services (Google Analytics, Yandex Metric), search the record on the links when using Google Tag Manager.
You can read more about regular expressions and their syntax here.
Redirecting the entire site to the new address:
Redirect from one page to another:
Redirect from www to without www:
Redirecting from HTTP to HTTPS:
Do not forget that when working with the file, the command occurs at the server level with Linux or Apache with the Mod_rewrite module activated.
You can also reduce the load on the server by changing the hpptd.conf configuration file. — redirect .htaccess.
CONFIGURING REDIRECTS IN THE CMS
For most CMS, there are plug-ins that allow you to easily configure redirects. The main difficulty is usually that you need to manually create a list of addresses for forwarding.
USING A PHP CONDITION
If you know the structure of a web project, understand PHP and the site is made on a CMS, then open the file index.php, and in the root of the engine write:
(the first line shows the old url, and the second line shows the new one)
You can also redirect PHP by sending headers:
In the root of the site, you will need to find the web.config file and insert it in the syntax section:
JSP (Java) redirect
This method is best suited for the correction of simple projects. You just write the code in a single file and add it to all the necessary pages. And here is the code itself:
(redirect to another site)
CGI script in PERL
Ruby on Rails
Redirect to nginx
If you need to change only one page on a simple static site, make an HTML redirect. Just add a meta tag inside.
In this example, we use a redirect to our site with a 10-second delay:
If we change the value from 10 to 1, the user will go to https://uaateam.agency/ with a second delay.
But it is better to do this only for simple sites, so you will spend a lot of time on large resources.
REDIRECTS BY ISSUE TYPE
Redirecting with or without www
Add these lines to the .htaccess file if you need to configure the main mirror:
You can also redirect from www using the syntax:
Linking index.php, index.html, index.htm, index.asp
Redirect from http and https
If we move to a secure protocol, we add:
Redirect from https to http
Linking duplicates with a slash at the end of the url
To delete a slash across the entire site you must use the code:
Code for the reverse effect:
Deleting several slashes or dashes in the address bar
Making a redirect with extra slashes to a page with a single slash:
To link the dash together write from www.site.com/catalog/page1.html:
To simplify the process, I recommend using services that generate redirects, just insert your data and immediately get the ready-made code:
Redirect one url to another address
The fastest page redirection to a new address:
With the saving of GET parameters
url before the parameter
the value after the parameter (instead of ?= put ^)
If some GET parameters are missing or have an arbitrary value, select this syntax:
Without saving GET parameters
For forwarding addresses site.ua/index.php to the main mirror site.ua:
REDIRECT TO A LOWERCASE URL
We know that the PS is case-sensitive, which is why developers try to add addresses in lowercase, but if something goes wrong, you can always use this redirect algorithm.
Write this code at the php script level:
From the internal page to the main page
Redirecting a folder
If the structure of the folder displayed in the url changes:
If the address of a folder that is outdated comes immediately after the site name, then use this syntax:
Please note that these options are most suitable for large tasks, but due to the specifics of some engines, they may need to be refined.
REDIRECT IS WHEN YOU CHANGE THE FILE EXTENSION
If your file extensions have changed due to moving to a different platform, you can use this formula:
WE LINK DOMAINS OR MOVE TO ANOTHER SITE
Redirecting all pages from one domain to the main page of another
Add the following lines to the .htaccess file of the site you are redirecting from:
(site.ua – the site that the redirect will lead to)
Redirecting to the main page from internal pages
Redirecting to the internal page from the main page
From subdomain to main domain
From pages in one domain to analogs in another
If you need to redirect to a different address after changing the url structure, try this code:
If there is no solution to the problem using syntax, I recommend contacting the developers of this resource, they will finish the above options with the features of your CMS. Also, in this case, it would be good to make a map of redirects.
This is all I have, I hope that this article will be useful to you and useful in your work. No matter how scary the redirect setup may seem to you, I assure you that when you try it, you will understand that there is nothing complicated about it.
I also advise you to read and learn the syntax of regular expressions in detail, as it will be useful to you in your work more than once.