What is a 301 redirect code and how does it affect SEO?

Last updated: June 20, 2021

What is a 301 redirect code?

A 301 redirect (opens in a new tab) signals to search engines that content has permanently moved to another URL. Because of the permanent nature of the 301 redirect, authority and relevance carry over to the redirect’s target.

When you need to redirect URLs, in most cases a 301 redirect is what you want. Because it carries authority and relevance over to another URL, it is an essential tool in every SEO expert’s toolbox.

301 redirect: permanently moved content
301 redirect: permanently moved content

Why should you use 301 redirects?

When your content moves, you want to make sure it affects your SEO performance as little as possible. That’s where 301 redirects come in.

If you don’t implement 301 redirects when content moves, both visitors and search engines will have trouble figuring out where that content moved to. Visitors hit a 404 page, and search engines can’t send any built up relevance and authority to the new URL. This drops your rankings dramatically.

Website visits going down
Are redirects hurting your SEO performance?

Check your website for excessive redirects, and incorrect configurations right now!

How does a 301 redirect work?

We’ll explain how 301 redirects work with a simplified example of a client that’s requested a redirected URL:

Step 1: Client makes a request

A client requests a URL from a server:

GET /old-url/ HTTP/2
Host: www.example.com

Step 2: Server responds

The server looks up the URL and finds that its content has been permanently moved. It replies with this to the client:

HTTP/2 301
location: https://www.example.com/new-url/

Step 3: Client makes a new request

The client requests the URL that the content has been moved to:

GET /new-url/ HTTP/2
Host: www.example.com

Step 4: Server responds to new request

The server answers that everything is OK, and sends the URL’s assets along as the payload:

HTTP/2 200

In which situations are 301 redirects commonly used?

301 redirects are commonly used when:

  • You’ve changed a page’s URL (see the example above).
  • You want to consolidate pages about the same topic.
  • You’ve changed a subfolder’s URL (e.g. https://example.com/old-folder/ to https://example.com/new-folder/).
  • You’ve moved a subdomain to a subfolder (e.g. https://blog.example.com to https://example.com/blog/).
  • You’ve changed domain names (e.g. example.com to example.io).
  • You’ve switched from HTTP to HTTPS (e.g. http://example.com to https://example.com)

You get the idea: any time content that carries some value moves, you want to ensure neither visitors nor search engines end up on 404 pages. That’s where redirects come in.

How do I create a 301 redirect?

In this section we’ll discuss creating 301 redirects on Apache, nginx, WordPress and Shopify.

Creating 301 redirects on Apache

On the Apache webserver, redirect rules are kept in the .htaccess file.

Here’s a simple example of implementing a 301 redirect on Apache to redirect /old-page/ to /new-page/:

<IfModule mod_rewrite.c>
RewriteEngine On
RedirectMatch 301 /old-page/ /new-page/
</IfModule>

Creating 301 redirects on nginx

On nginx, redirects are kept in your nginx.conf file.

Here’s how to implement our example 301 redirect on nginx:

server {
    rewrite ^/old-page/$ /new-page/ permanent;
}

Creating 301 redirects on WordPress

The easiest way to create 301 redirects on WordPress is through a plugin such as Redirection (opens in a new tab).

Let’s use that plugin to implement a simple redirect from /old-url/ to /new-url/:

  1. Log on to the WordPress admin environment.
  2. Go to Tools > Redirection.
  3. Fill in the URL you want to redirect in the Source URL field.
  4. Fill in the redirect’s target in the Target URL field.
  5. Hit the blue Add Redirect button, and you’re done.

    Creating 301 redirects on WordPress

Creating 301 redirects on Shopify

Shopify’s SEO toolbox comes with a built-in redirect manager. And when you change page URLs, it’ll always ask you whether you want to add a 301 redirect.

You can add redirects manually, or import a list of redirects. Here’s how to implement a simple 301 redirect:

  1. Log on to the Shopify admin console.
  2. Go to Online Store > Navigation > 🔗URL Redirects.
  3. Click on the blue Create URL redirect button.
  4. Define the redirect source URL in the Redirect from field, and define the redirect target in Redirect to:

    Creating 301 redirects in Shopify

Unless you’re on a hosted platform where you can’t access the web server configuration, creating redirects in a CMS should be treated as a last resort.

It’s highly recommended to create 301 redirects at the web server level, because:

  1. It’s much faster.
  2. It’s easy to produce conflicting redirects if you’re managing them in two places. Managing redirects is tricky enough; don’t complicate it further.

Creating 301 redirects directly on CDN

There is one other great way—unknown to most SEOs—to implement 301 redirects: via a CDN like Cloudflare or Akamai. Load times decrease dramatically when you’re implementing redirects directly on a CDN, because a client only has to make one request.

See below for how to implement 301 redirects using Cloudflare.

  1. Log into your Cloudflare account.
  2. Click on the Cloudflare account for which you want to implement redirects.
  3. Click on the Page Rules app.
  4. Under Page Rules, click Create Page Rule.
  5. Under If the URL matches, enter the URL or URL pattern that you want to redirect.
  6. Next, click Add a Setting.
  7. Choose Forwarding URL from the drop down menu.
  8. Click Select Status Code and choose 301 — Permanent Redirect.
  9. Enter the redirect target in the field Enter destination URL.
  10. Hit Save and Deploy.

    Creating 301 redirects using Cloudflare

Useful tools

Here are some useful tools that will help you set up, redirect, and diagnose redirect issues.

Frequently asked questions

What happens to a page that’s 301 redirected?

While a redirected page can still exist within a Content Management System, it won’t be available to visitors and search engines anymore.

Search engines will consolidate the old URL with the new URL and hide the old URL in their search results. The time the engines need before they completely hide the old URL varies; in practice we see this take anywhere from a few days to a few months.

Can you change a 301 redirect?

Yes, by adjusting the server configuration files as described above, or by adjusting redirects that are configured through a plugin, you can change them at will.

Be careful when changing 301 redirects though; it’s easy to make mistakes that cause redirect loops or URLs that suddenly stop redirecting. Carefully test any adjustments you’ve made.

Are redirects hurting your SEO performance?

Redirects may be holding back your SEO performance.
Check your website for excessive redirects right away!

Can you have too many 301 redirects?

If we’re talking about the number of redirects that are implemented for a website, then the answer is “no” 99.99% of the time.

If we’re talking about chained redirects, such as when URL A redirects to URL B, which in turn redirects to URL C and so on, then “yes.” Chained redirects are bad from both an SEO viewpoint and a visitor viewpoint, because crawlers and browsers will stop following the redirects.

How long is it before my 301 redirects take effect?

That depends on how much attention search engines can give your website—also called its crawl budget.

It’s common for redirects implemented on authoritative sites to be picked up faster than those on smaller, less authoritative sites.

As a rule of thumb, count on a few days to a few weeks.

How long should you keep 301 redirects?

You need to keep 301 redirects in place indefinitely. If you remove them, when visitors and search engines request the old URL, they won’t be forwarded to the new URL anymore.

This leads to a poor user experience for visitors—and search engines will stop attributing the value of the old URL to the new URL.

Interestingly, old domains that aren’t renewed and thus stop redirecting are a common reason why rankings drop. Hold on to old domains that carry value, and keep your 301 redirects going!

Are there situations where you shouldn’t implement 301 redirects?

Yes, for example when content hasn’t been moved permanently. In that case, you need to use a 302 redirect.

When you use a 302 redirect, both URLs remain indexed, and browsers will not cache the redirect.

How do 301 redirects affect browser behavior?

Browsers cache 301 redirects aggressively. When you remove a 301 redirect, and you browse to the URL that was previously 301-redirected, it can look like the redirect is still in place, it’s really just that your browser has cached the redirect.

To fix this, you need to purge the browser’s cache. (Even a “hard refresh” using CMD + R or CTRL + F5 isn’t enough.)

Read the full Academy article to learn everything about Redirects