A Comprehensive SEO Guide to 301 Redirects

Author

As your site grows in size, the location of some pages will inevitably change. You might need to delete old irrelevant pages, migrate an entire site or delete content that no longer makes sense. Instead of losing the traffic that these pages generate, you can use a 301 redirect. In this guide, we’re going to answer key questions when working with this crucial redirect, such as:

  • What does 301 moved permanently mean?
  • What’s a forward type permanent (301) temporary (302)?
  • What types of redirects exist?
  • Do 301 redirects affect SEO?
  • So much more.

Let’s start with the basics first and work our way through the world of HTTP 301 response codes and how to use them like a pro.

What is a 301 redirect status response code?

An HTTP 301 response happens behind the scenes between your browser and the server that you’re trying to access. Let’s look at an example of how this works. 301 Redirect Example | Mazeless Example: http://www.mazeless.com redirects to the secure version https://www.mazeless.com When you try to access the first link, our server:

  • Sends your browser information
  • Responds with “This page is permanently moved”
  • Sends the new location

Your browser then redirects to the new URL. As a user, you likely don’t even know that an error 301 occurred.

Types of redirects

Communication between browsers and servers happens with every request. While we’re focusing on 301 redirects, it’s important to know that the following redirects also exist:

  • 302: The difference between a 301 redirect vs. 302 redirect is that a 302 is a temporary redirect.
  • 307: The same as a “Moved Temporarily” redirect, like the 302, though it’s not used often.
  • 308: Works the same as a 301 redirect and is treated as such by Google.

How do I set up 301 redirects?

You can set up a 301 redirect using a few methods: Can you do a JavaScript 301 redirect? 301 HTTP response is sent by the server and JavaScript is executed on the client side. So JS is not a good option for SEO redirects. JS 301 redirect is followed by search engines. One issue is that if a user’s browser has JavaScript disabled, it won’t work. You can set up a JavaScript 301 redirect like this:

<html>
	<head>
		<script>
			window.location.replace("https://www.mazeless.com/");
		</script>
	</head>
</html>

However, note that the JavaScript redirect 301 should be used as a last resort if you don’t have access to meta refresh or server-side redirects. Meta Refresh Meta refreshes are done on a page-by-page basis and look something like this:

<meta http-equiv="refresh" content="0; url=https://www.mazeless.com/">

Server-Side Redirect An optimal 301 redirect will occur on the server-side using either server-side scripts, a 301 redirect htaccess file or something similar. For example, in PHP, the redirect may look something like this:

 <?php header('Location: http://www.example.com/', true, 301); exit(); ?> 

What is a 301 .htaccess redirect?

A 301 redirect using .htaccess means that a .htaccess file is used to make the redirect. This redirect is for Apache servers and will look like this:

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/

However, you can use regular expressions and make .htaccess files rather complex. A good guide on using .htaccess redirects can be found on DreamHost.

Do 301 redirects affect SEO?

If GoogleBot got an http 301 response at crawl time, does it impact SEO? It won’t result in lost SEO value, but it can be used to shape certain pages into authority pages on your site. Let’s go through a few common questions relating to 301 redirects and SEO.

Are JavaScript redirects bad?

Yes and no. It’s better to use a .htaccess or server-side redirect than a JavaScript redirect, but as Google states, “Only use JavaScript redirects if you can’t do server-side or meta refresh redirects.”

How to Redirect a URL in WordPress?

WordPress has a lot of plugins that you can use to handle redirects. If you need a 301 redirect tool that’s designed for WordPress, try the following plugins:

If you have access to the server, you can use a .htaccess file for redirecting. An example of redirecting one page to another is below:

Do 301 Redirects Pass Link Juice?

Yes, they do. However, you might not receive 100% PageRank. Matt Cutts, former Head of Webspam at Google, said the amount of PageRank that dissipates through a 301 is the same as with a link. So, you might lose some link juice, but the impact is minimal at best. You can see a great video on the topic by Matt directly below: However, Google seems to have changed its stance and states that PageRank doesn’t get lost with a 3## redirect any longer. John Mueller from Google Switzerland says that you must redirect 404s to somewhere relevant. For example, if you redirect /cats/ to /fish/, that will be seen as a soft 404 error and not pass any value. Instead, if /cats/ is redirected to /kittens/, it will pass value. In fact, there’s a great video with John on this very topic below:

How to Use 301 Redirects for Link Building?

An issue with 301 redirect Google ranking manipulation is that Google is well aware of these tactics. The search giant doesn’t want you to purchase a domain, perform a 301 redirect, and manipulate the search results. Instead, the best 301 redirect SEO practice is to:

  • Redirect older deleted pages back to existing pages where it makes sense

Why? When the content is similar and of value to the user, it will pass link juice along. You can also merge two pages together that were underperforming. For example, say we had two pages on 301 redirects that didn’t perform well. We might redirect those pages to this guide to consolidate authority. A few times you may want to do this is when:

  • Keyword cannibalization exists and you can redirect content to rank higher for a keyword.
  • Merging pages together into helpful guides makes sense for your audience.
  • You create revamped pages and the old URLs don’t make sense to use. In this case, you can redirect them to the new pages.

When you redirect content on your own site, it’s possible to consolidate your authority and boost your rankings in a similar way to link building. But without the additional work.

In which situations are 301 redirects commonly used?

What’s the difference between a 301 vs. 302 redirect for SEO? When should you use a 301 redirect over the many other types available?

When should you use 301 redirects?

A 301 redirect should be used in the following cases:

  • A page that no longer exists has been removed and you want to pass its value to another relevant page
  • You want to consolidate pages or content to new URLs
  • You redirect a site
  • You are changing from non-www to www
  • You are changing from HTTP to HTTPs
  • You needed to change URLs for a page
  • The redirect is permanent

If the redirect is only temporary, you’ll want to use a 302 redirect or something similar.

301 Redirects vs. Canonical Tags

A 301 redirect and canonical tag are similar, but they’re not the same. A 301 redirect tells search engines that the page, folder, site or file no longer exists and that you can find this resource at another location. The redirect is also permanent. However, Canonical attributions are different because the “rel=canonical” tag is used when you have:

  • Multiple pages with the same content
  • Content on certain pages that is very similar

For example, if you sell a product that may be in multiple categories, it may be found on many product pages. Since these duplicate pages exist, using a canonical tag makes sense.

Migrating Your Site to a New Domain

You can migrate one site to another with precision using a 301 redirect. Let’s take a look at how this is done using Apache’s .htaccess file.

Redirect an old page to a new page

A bulk 301 redirect generator works great if you have multiple pages to redirect, but you can also do the following:

Redirect 301 /pagename.php http://www.domain.com/pagename.html

Redirect an old domain to a new domain

If you want to redirect an entire domain and all of its content to another domain, you can use the example below:

Redirect 301 "/" "http://www.new.com"

You can also use 301 moved permanently to Facebook for businesses that abandon their website and move to Facebook instead.

Redirect entire domain from non-www to www

If you want to have www in front of your site name, you can do it with just three lines of code in your .htaccess file:

RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Redirect entire domain from HTTP to HTTPS

When going from HTTP to HTTPS, which is something all sites should be doing, you can use the code below:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirect entire domain from non-www to www and HTTP to HTTPS

Similar to the last point, you can redirect a non-www and HTTP site to www and HTTPS with the following code:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect www to non-www with SSL/HTTPS via .htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

301 Redirects on Apache Servers

Apache uses .htaccess files for redirects, and you can use complicated regular expressions to refine how your redirects work. Since regular expressions can be very complex, you may want to read through a few of the following guides:

Common 301 Redirect Mistakes & How to Avoid Them

Redirect mistakes are often difficult to pinpoint because a small space or letter capitalization issue can cause a redirect not to work. The easiest way to avoid errors is to use a plugin or software to create redirects. A few additional tips for avoiding redirect mistakes are:

  • All URLs are case-sensitive. You need to either enter the exact URL or use the “NC” rule in your .htaccess file.
  • Create a database of all redirects to help avoid redirect loops and chains.
  • Test all redirects you create to ensure that they’re working properly.

If you find that your 301 redirects aren’t working properly, use the tips below.

How to fix existing 301 redirect issues on your site

If you find that you have a problem with 301 redirects on your site, you’ll want to look over your implementation and make sure that everything is 100% right. A few tips include:

  • Spelling
  • Destination
  • Capitalization

Ensure your HTTP version is pointing to the HTTPS version of your site. Once this is done, you’ll want to do a few things:

  • Any pages in your sitemap that have a 301 redirect should be removed since you don’t want Google to keep looking for the page after it’s gone.
  • Check the page for redirect chains. For example /page1/ goes to /page2/ and that goes to /page3/. Instead, redirect /page1/ to /page3/ and /page2/ to /page3/.
  • Pages that are stuck in a redirect loop will need to be reviewed and the error corrected by verifying that two directs aren’t pointing back to each other and restarting the redirect cycle.
  • Redirect pages that go to a 404 error page aren’t providing your site with maximum value. If you find that there’s a broken redirect, be sure to fix it by either creating the 404 page or pointing the redirect to a new page.

Monitoring your site’s redirects can be very complicated. Auditing your site using automation is critical. Click here to give our tool a try to master redirects.

How to resolve 301 moved permanently error

If you’re running into an error, use the tips above to try and fix the redirect error. You can also:

  • Check Your Htaccess Files for Errors in URL Linking
  • Run audit tools to learn what’s causing the error
  • Check Your Server Logs
  • Check Your Sitemap

Always back up your files and .htaccess file before editing so that if you make matters worse, you can restore the old version.

Summary

Using 301 redirects for SEO takes time, and it shouldn’t be done lightly. You must spend time to verify that each redirect works, has a purpose and is a good solution for your site. If your site has pages that need to change their locations or pass value from one logical page to another, 301 redirects can help.

Relevant Insights