What is a 301 redirect code and how does it affect SEO?
What is a 301 redirect code?
A 301 redirect 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.
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.
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/
tohttps://example.com/new-folder/
). - You’ve moved a subdomain to a subfolder (e.g.
https://blog.example.com
tohttps://example.com/blog/
). - You’ve changed domain names (e.g.
example.com
toexample.io
). - You’ve switched from
HTTP
toHTTPS
(e.g.http://example.com
tohttps://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 .
Let’s use that plugin to implement a simple redirect from /old-url/
to /new-url/
:
Creating 301 redirects on WordPress
- Log on to the WordPress admin environment.
- Go to
Tools
>Redirection
. - Fill in the URL you want to redirect in the
Source URL
field. - Fill in the redirect’s target in the
Target URL
field. - Hit the blue
Add Redirect
button, and you’re done.
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:
Creating 301 redirects on Shopify
- Log on to the Shopify admin console.
- Go to
Online Store
>Navigation
>🔗URL Redirects
. - Click on the blue
Create URL redirect
button. - Define the redirect source URL in the
Redirect from
field, and define the redirect target inRedirect to
:
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:
- It’s much faster.
- 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.
Creating 301 redirects on Cloudflare
- Log into your Cloudflare account.
- Click on the Cloudflare account for which you want to implement redirects.
- Click on the
Page Rules
app. - Under
Page Rules
, clickCreate Page Rule
. - Under
If the URL matches
, enter the URL or URL pattern that you want to redirect. - Next, click
Add a Setting
. - Choose
Forwarding URL
from the drop down menu. - Click
Select Status Code
and choose301 — Permanent Redirect
. - Enter the redirect target in the field
Enter destination URL
. - Hit
Save and Deploy
.
Useful tools
Here are some useful tools that will help you set up, redirect, and diagnose redirect issues.
- Audit 301 redirects with ContentKing
- Aleyda Solis’ htaccess redirect generator
- htaccess to nginx converter
- Chrome plugin: Redirect path
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.
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 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.)