301 Redirects in SEO: The Complete Guide

2,270
8 min
Share: twitter Copy
301 Redirects in SEO: The Complete Guide

The 301 redirect is one of the most important aspects of SEO. A 301 is equivalent to a followed link – the only one on the page at that. It transfers the full “link juice” – trust and authority, if you will – of the source page to the destination page.

Even though a redirect is a simple web construct and has been around since the web itself, there are a lot of misunderstandings and uncertainties about how to use it for SEO. SEO folks tend to have a lot of questions about how redirects work and Googlers find themselves clarifying the same things over and over again.

https://twitter.com/johnmu/status/1484234387243864073

So here’s my attempt to explain the ins and outs of redirects, especially the 301 (permanent redirect) directive. Fasten your seatbelts.

What is a redirect?

A redirect is simply a way to take users from an old, outdated page to its new version. Technically, redirects are HTTP response codes (from the server that digs up and displays the page in question to a browser that asks for it) numbered 3xx. Essentially, a 3xx redirect is a “directive” or an instruction to the web server to replace the URL that the user types into the browser with its new equivalent. Redirects can be temporary (302) or permanent (301).

Redirects are invaluable in SEO. They prevent duplication of content as well as broken links that confuse bots and users alike. They help you maintain your rankings and visibility in the SERPs when you need to replace an existing page with a new one.

To show you a simple example, click on https://serpzilla.com/blog/ and notice the URL when the post appears in your browser. What do you see?

Types of redirects

Okay, the IETF RFCs will tell you that there are 8 types of redirects – all the way from 301 to 308. But the only ones you need to know of (and use) are 301 (permanent) and 302 (temporary).

A 301 redirect tells Google that the page in question (along with its content) has moved permanently to a new URL. A 302 redirect tells Google that the page has moved temporarily to a different URL and it is expected to come back to this location sometime in the future.

In the early days, SEO experts believed that 3xx redirects didn’t pass on the full PageRank to the destination URL, but in 2016 Gary Illyes of Google confirmed that they do:

The need for 301 redirects

So when do you need a 3xx redirect? How is it important in SEO? The three major situations that call for a 301 redirect are:

1) Technical SEO

301 redirects are used to stop duplication and canonicalization in three fundamental ways:

  • Redirecting all URLs running HTTP to those fortified by HTTPS

    For example, if you type the URL https://serpzilla.com/ in your browser,you’ll find it automatically goes to https://serpzilla.com/
  • Redirecting the www version of a domain to one without www (or vice versa)

For example, if you type the URL https://serpzilla.com/ in your browser,you’ll find it automatically goes to https://serpzilla.com/

Remember, Google consider all of the above URLs as completely different pages. However, the content on them will be the same, resulting in duplication. That’s why it is important to choose one version and redirect the other to it. The choice is yours – one isn’t necessarily better than the other, but our personal preferences are that we don’t use www at the beginning of the domain and we add trailing slashes to all our URLs. As for HTTPS, it is mandatory.

2) Moving a domain

When a business changes its domain – usually to introduce a new brand or product line – the URLs in the old domain need to be redirected to their equivalents on the new domain.

3) SEO techniques

A common grey-hat SEO practice (which works well in certain cases) is buying high-authority domains that have just expired and redirecting them to your “money” site. Many experienced SEOs use special services to buy expired domains that used to have thematic content related to their niche as well as a great backlink profile, restore the content using archived records from web.archive.org to a new site they’ve specially registered just for rankings, and setting up 301 redirects from the old URLs on the expired domain to their appropriate equivalents on the new one.

Boom! A thousand backlinks in an instant!

How to set up a 301 redirect

There are multiple ways to set up 3xx redirects – using a script, editing the PHP code, via CMS plugins or add-ons, and by modifying the .htaccess file. Since the last option is the most common one, we’ll talk about it in detail.

First, what is a .htaccess file? In Linux/Apache servers, the .htaccess is a distributed configuration file that allows you to make changes that apply on a per-directory basis on the web server. It contains one or more configuration directives that apply to the directory in which the file is placed as well as all its sub-directories.

The .htaccess is usually accessed via FTP or SSH. You simply back it up, download it, edit it and upload the modified version. Try and do this at times when there is minimal traffic to your domain. Warning: Do not attempt to fix the .htaccess file through the CMS – if something goes wrong, the admin panel itself will stop working and you’ll be shut out of the site.

Don’t see a .htaccess file? It could be due to one of two reasons:

  1. You don’t have a .htaccess file. It hasn’t been created yet. Just open Notepad (Windows) or TextEdit (Mac), create a new text file and save it with the name .htaccess (remove the default .txt extension) in the public_html directory.
  1. Your site isn’t running on an Apache web server. Web servers come in different flavors – Linux/Apache, Windows/IIS and Nginx are the most common implementations. Only the Apache servers use .htaccess.

Here are a few lines of code that show how to implement 301 redirects at various levels using the .htaccess file:

  • Redirect a specific page or URL:
Redirect 301 /old/old.htm http://new-site.com/new.html
  • Redirect the whole site:
RedirectPermanent / http://new-site.com
  • Redirect a specific directory:
RedirectPermanent /old-directory http://new-site.com/new-directory/
  • 301 redirect from a www site to a non-www site:
RewriteCond %{HTTP_HOST} ^www.site\\.ru$ [NC]RewriteRule ^(.*)$ [R=301,L]

or

RewriteCond %{HTTP_HOST} ^www\\.(.*) [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  • 301 redirect from /index.php to root:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://site.com [R=301,L]
  • 301 redirect from a URL with a trailing slash to a URL without a slash:
RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_URI} !\..{1,10}$RewriteCond %{REQUEST_URI} !(.*)/$RewriteRule ^(.*)$ http://www.site.ru /$1/ [L,R=301]

or

RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_URI} !\..+$RewriteCond %{REQUEST_URI} !/$RewriteRule (.*) http://www.site.ru/$1/ [R=301,L]
  • 301 redirect from http to https:
Rewrite Engine On
RewriteCond %{SERVER_PORT} ^80$ [OR]
RewriteCond %{HTTP} =on
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
  • 301 redirect from https to http:
Rewrite Engine On
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
  • Remove the slash with a 301 redirect:
RewriteEngine OnRewriteCond %{HTTP_HOST} (.*)RewriteCond %{REQUEST_URI} /$ [NC]RewriteRule ^(.*)(/)$ $1 [L,R=301]
  • Add a slash using the 301 redirect:
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_URI} !(.*)/$RewriteRule ^(.*[^/])$ $1/ [L,R=301]

Challenges and common errors

There are certain pitfalls and best practices that you need to keep in mind when working with redirects.

  • Redirects are not a way to solve HTTP errors on your site. Do not redirect pages with 404 Page Not Found or other errors to other pages, not even temporarily. If you permanently delete a page from your site, make sure it returns a 410 status. Try to resolve 4xx errors by removing or correcting broken links. Also make sure that you aren’t redirecting a good page to one that returns a 404.
  • Watch out for redirect loops or circular redirects. These can occur due to incorrect configuration of the .htaccess file or a CMS plugin. A redirect loop occurs when URL A is directed to URL B, which in turn redirects to URL A. This results in a ERR_TOO_MANY_REDIRECTS error.
  • A similar problem is a redirect chain, which occurs when URL A is directed to URL B, which points to URL C, which in turn points to URL D, and so on. This happens when redirects are added over time. Make sure to check your redirect file periodically and delete older redirects.
  • Keep the size of your redirect list to a minimum. Know that the server has to go through the entire list before returning any given URL. A huge redirect list increases the load on the server, lowering the page loading speed, which is an acknowledged ranking factor in Google.

Over to you

Even experienced SEOs seldom realize the full implications of a simple thing such as redirects. We often take them for granted and never check if they’re working correctly or not. However, you should make them part of your regular SEO audits, so that your site structure and page experience are always at optimal levels.

  • Alex Sandro

    Senior product manager at Serpzilla.com. SEO and linkbuilding expert. More than 10 years of work in the field of website search engine optimization, specialist in backlink promotion. Head of linkbuilding products at Serpzilla, a global linkbuilding platform. He regularly participates in SEO conferences and also hosts webinars dedicated to website optimization, working with various marketing tools, strategies and trends of backlink promotion.
5
Share: twitter Copy

What are your thoughts?

What are your thoughts?
Increase the visibility of your website with links
Sign up
Read more