News and Insights
Redirect 301: The mega guide
March 13, 2019
- 1 – What is a 301 redirect?
- 2 – What is a 301 redirect for?
- 3 – How do I create a 301 redirect?
- 4 – What are 301 redirect chains?
- 5 – Most common 301 redirects
- a. Redirect from non-WWW to WWW or vice versa
- b. Redirect from 5.2 Redirect from http to https or vice versa
- c. Redirect without www and http to www and https
- d. Redirect Slash to the end of the URLs
- e. Redirect a full domain to a new domain
- f. Redirect a full domain to the homepage of another domain
- g. Redirect the homepage to another URL
- h. Redirect a full directory
- i. Redirect a specific page
- 6 – How do I check a 301 redirect?
- 7 – Conclusions about redirections
What is a 301 redirect?
To start talking about 301 redirects, we must first describe what redirects are exactly. In short, a redirect means to take visitors from one web page to another (either from the same website or from another second website) automatically.
There are several types of redirects but in short, we could summarise by saying there are “temporary” redirects and “permanent” redirects.
A 301 redirect is a permanent redirect from one page to another, so when we use this type of redirection, we are telling search engines that this change from one URL to another is definitive.
What is a 301 redirect for?
As mentioned, a 301 redirect tells search engines we’ve made a definitive change from one URL to another.
What’s next? Google will interpret that URL1 (the one we want to redirect) will now become URL2 and therefore Google will pass the link equity of URL1 to URL2 and count the links as of this second URL.
As an SEO agency, we use permanent redirects when dealing with complex website migrations or any change in the website architecture in order to pass the link equity from the old URL.
Full domain redirects
Not all redirects will have the same impact. If you redirect a cosmetic website which is currently ranking well for cosmetic queries and decide to redirect the whole domain to a car-rental website, it doesn’t look natural. Remember to redirect only relevant websites i.e. industry-related sites.
Using 301’s to unify websites
Let’s say we have three luxury car websites; Porsche, Ferrari and Lamborghini, we can unify the 3 of them into a single luxury car website. If done well, we will be able to unify the three smaller websites into a much larger one. Obviously if not implemented correctly, we could potentially lose the SEO value of the three smaller websites.
Avoid keyword cannibalisations with redirects
Another great use of redirections is to avoid keyword cannibalisation. If we have a URL1 ranking by a certain keyword and a URL2 also ranking by it … we can redirect one of these URLs to the other one so that we only have a single result and do not lose the strength of both URLs.
URL redirections to remove
Another good use of 301 redirects is when for example an e-commerce website wants to eliminate a product because they aren’t going to sell it anymore and that URL is ranking well or has good incoming links (also known as backlinks).
If we remove that URL we will lose its ‘Page Authority’. However, if we have another related product and we do a 301 redirect to it, we will take advantage of both the strength and the links of the original URL.
How to write a 301 redirect
If you are at this stage you will already have a clear understanding about what page you want to redirect and where you want it to go. But how do you implement the redirect?
Below we explain the different options with their pros and cons.
htaccess
This type of redirect is done by modifying the .htaccess file. The .htaccess file is a configuration file read by the server that allows you to do many things like rewrite URL’s.
The great thing about this file is that we can perform redirect patterns and redirect complete directories with only one command. That is, it makes our work much easier if we know how to use .htaccess redirects correctly.
We will explain later how to perform some of the most common redirects using .htaccess.
PHP
This type of redirection is done directly at PHP programming level and therefore you have to place the code inside the specific URL that we want to redirect.
See an example below:
header("Status: 301 Moved Permanently");
header("Location: http://www.myweb.com");
The downside of this type of redirect is that if we use a CMS platform like WordPress, it will be fairly complicated to implement as we will need to edit the site files which could introduce problems in future if we forget where exactly we have placed that redirection code.
HTML
In html we can use ‘meta refresh’ to create redirects. After a few seconds, the page is “updated” and redirected to a second URL.
meta http-equiv="refresh" content=”0: url=http://www.myweb.com/”>
This type of redirect is not technically a 301 and therefore does not pass link authority.
JavaScript
In JavaScript we can also create a redirection for example using this code:
window.location.replace ('https://www.newurl.com');
This is also not technically a proper 301 redirect and therefore will not pass authority. The reason for this is the 301 HTTP status code is created at the server side and Javascript is executed at the browser level. When the content is loaded to the browser, Javascript will take effect and redirect users to a new content but the page itself will remain status code 200, not 301.
The most common way of implementing 301 redirects is using .htaccess. You need to have access to your server and apache configuration file. If you don’t have access you’ll have to reach out to your hosting company and request it.
What are 301 redirect chains
It is a series of consecutive redirects that go from one URL after another such as URL1 -> URL2 -> URL3 -> URL4 and so on.
To 301 redirect pages using the .htaccess file, you will add a line to the file that tells the server what to do. What are the most common 301 redirects? We will show you a few of the most commonly used 301’s using the .htaccess file.
301 Redirect from non-WWW to WWW or vice versa
Search engines consider http://myweb.com and http://www.myweb.com different websites.
Ideally you should pick your preferred URL and implement a 301 redirect on the other. It would make sense to pick the URL with the stronger back link profile. You can check which domain has the stronger backlink profile by using any SEO tool, for example, Moz, SEMrush, Ahrefs or something similar.
Having this kind of redirect in place is very important to avoid duplicate content and allows you to effectively consolidate all of your link popularity to a single URL. This consolidation will serve to increase your website’s chances of obtaining and maintaining top rankings.
Should you want to redirect from http://myweb.com to http://www.myweb.com you’d need to paste the following code into the .htaccess file (remembering to change http://www.myweb.com to your website name):
RewriteCond %{HTTP_HOST} ^myweb.com [NC]
RewriteRule (.*) http://www.myweb.com/$1 [R=301,L,QSA]
Should you want to redirect from http://www.myweb.com to http://myweb.com you’d need to use the following code:
RewriteCond %{HTTP_HOST} ^www.myweb.com [NC]
RewriteRule (.*) http://myweb.com/$1 [R=301,L,QSA]
Redirect from http to https or vice versa
This redirect is very helpful in the event that you don’t want to or can’t use a WordPress plugin:
If we want to redirect from http://www.myweb.com to https://www.myweb.com:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.myweb.com/$1 [R=301,L,QSA]
If we want to redirect from https://www.myweb.com to http://www.myweb.com:
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.myweb.com/$1 [R=301,L,QSA]
Redirect without www and http to www and https
If we want to redirect from http://myweb.com to https://www.myweb.com (2 things at the same time – the http to https and addition of www) we can do it in 2 steps with 2 codes:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^myweb.com
RewriteRule ^ https://www.myweb.com%{REQUEST_URI} [L,R=301]
Redirect slash to the end of the URLs
Sometimes websites are able to load with the slash ‘/’ at the end or without it, as minor as this seems, it can generate duplicate URLs. While Google doesn’t consider these URLs as duplicate content its best practice to have them redirect.
The code to redirect http://www.myweb.com/something to http://www.myweb.com/something/ is:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*) http://www.myweb.com/$1/ [R=301,L,QSA]
The code to redirect http://www.myweb.com/something/to http://www.myweb.com/something is:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ http://www.myweb.com/$1 [R=301,L,QSA]
Redirect a full domain to a new domain
If you want to redirect a complete domain with all its architecture like http://www.mydomain.com to http://www.newdomain.com:
Redirect 301 / http://www.newdomain.com/
NOTE: Don’t forget to add ‘/’ at the end of newdomain.com if you want to redirect all the architecture of internal URLs correctly.
Redirect a full domain to the homepage of another domain
In some cases, people will redirect an entire domain’s URLs (let’s call this website 1) to the homepage of a new website (website 2). This is something we do not recommend, especially for large websites, because you would be redirecting so many URLs to one destination. It’s much better to map the URLs from website 1 to the most relevant pages on website 2.
If however you do choose to redirect a full domain to the homepage of another site you can do this as follows:
Redirect from http://www.myweb.com and all their URLs to http://www.newdomain.com:
RedirectMatch 301 (.*) http://www.newdomain.com/
Redirect the homepage to another URL
If we want to redirect the homepage of our domain to an internal section of the web or to another section of another web such as http://www.myweb.com/ to http://www.myweb.com/blog/ the code would be something like this:
RedirectMatch 301 ^/$ http://www.myweb.com/blog
Redirect a full directory
If we want to redirect a full directory to another one e.g.: http://www.myweb.com/directory/ to http://www.myweb.com/newdirectory/ this piece of code would make it possible:
Redirect 301 /directory/ http://www.myweb.com/newdirectory/
Also if we want to redirect from a subdirectory like http://www.myweb.com/directory/subdirectory/ to http://www.myweb.com/directory/newsubdirectory/:
Redirect 301 /directory/subdirectory/ http://www.myweb.com/directory/newsubdirectory/
Redirect a specific page
If we want to redirect only a specific page like http://www.myweb.com/page-x/ to http://www.myweb.com/page-y/:
Redirect 301 /page-x http://www.example.com/page-y
How to check a 301 redirect
To review the 301 redirect has been implemented correctly simply type the URL you have redirected and see if this now points you to the new corrected page.
It’s also very important to check the URL returns the 301 code. You can do this by using a tool like Screaming Frog Spider or using this free online redirect checker http://www.redirect-checker.org You will only have to insert the redirected URL and check all seems correct.
Conclusions about redirections
301 redirects are a vital part of any SEO audit and when implemented correctly can positively impact user experience, SEO and conversion rates.
This guide is inspired by the redirect guide from Spanish SEO David Ayala.
If you have any questions about redirects or need us to help you implement them, then get in touch with us today!
TAGS: Technology