How to create a 301 redirect in WordPress

Do you need to create a 301 redirect in your WordPress site? You’ve come to the right place! We’ll show you how to set up 301 redirects using three methods. Do you know if you need to use a redirect or whether a 301 redirect is right? No worries, we’ll explain that, too.

Redirects in a nutshell

The name ‘redirect’ says it all: It sends visitors traveling from a specific page to an alternative one instead. Or, if there’s no alternative, an HTTP header (similar to redirects) can make that clear to users and search engines. It’s like registering a change of address when you move house. What if an old friend visits your old home to visit you? A redirect is like a front door note telling your visitors where you live now. Any time you change a URL or delete a page, you should think about redirects.

Different redirects serve different purposes. Since this post is all about 301 redirects, let’s look at some situations where you might need to use one.

When should you use a 301 redirect?

A 301 redirect should be used when:

  • You’ve permanently deleted a page on your site, but you have another similar page you want to send users to instead
  • You’ve changed the URL of a page that was already published
  • You’re moving your site to a new domain
  • You’re changing your URL structure, e.g. changing from HTTP to HTTPS, or removing ‘www’ from the start of your URL

These are some of the more common reasons for using a 301 redirect, but other situations require redirecting, too. And besides that, there are other redirects and HTTP headers you can use in other situations. For instance, if you permanently delete a page and there is no suitable replacement or substitute you can send users to, then a 410 redirect is what you need to use. We have another post where you can read more about which redirects to use in which situations.

Option 1: Create a 301 redirect on the server

To set up a 301 redirect using .htaccess for the given example URLs, you need to add a specific line to your site’s .htaccess file, which is located in the root directory of your WordPress installation. Here’s how you can do it:

  1. Access your server. Access your site’s files using an FTP client or your web host’s file manager. You can also access and edit your .htaccess file from inside the Yoast SEO tools section.
  2. Locate the .htaccess file: The .htaccess file is usually in the root directory of your WordPress installation.
  3. Edit the .htaccess file: Open the .htaccess file with a text editor.
  4. Add the redirect rule: Insert the following line at the end of the file to create the redirect. This rule indicates that requests to /page-1 should be permanently redirected to /page-2.
Redirect 301 /page-1 /page-2
  1. Save changes: If you use an FTP client, save your changes to the .htaccess file and upload them back to your server.

Using this rule, any request to https://example.com/page-1 will be permanently redirected to https://example.com/page-2. The 301 status code indicates to search engines and browsers that the redirect is permanent. Note that this approach assumes the URLs follow the format /page-1 and /page-2 without additional subdirectories. You can adjust the path if your URLs are different.

These configurations can become unmaintainable over time, especially if you’re an avid blogger trying to improve your posts’ SEO. You must also log in to your server over FTP, edit the files, and re-upload them whenever you add a new redirect. That’s why, generally speaking, this method is not considered the way to go.

Option 2: Create a 301 redirect with Cloudflare

Most of us already use Cloudflare in one form or another, so you know that it offers a wide array of tools to help our websites perform. For instance, it comes with a Rules feature where you can set various options related to your website cache. You can also find various redirect options here; this will help you guide up redirects for everything from HTTP to HTTPS to single redirects for individual pages.

It’s easy to set up redirects through Cloudflare. Here’s how that works:

  1. Log into your Cloudflare account: Go to the Cloudflare dashboard and select your account and domain. Then, select Rules and Overview.
  2. Create a redirect rule: Select Create rule and then choose Redirect Rule. In the Rule name field, you might name it something like Redirect Page 1 to Page 2.
  3. Define the matching criteria: Set a wildcard pattern and set the Request URL to https://example.com/page-1. This means any traffic to example.com/page-1 will be matched for redirection
  4. Set the redirect parameters:
    • Target URL: Enter https://example.com/page-2 as the redirect destination.
    • Status code: Select 301 to indicate a permanent redirect.
    • Preserve query string: Decide based on your preference; enable this option if the original URL’s query string should be retained. When you choose to preserve the query string in a redirect, you keep any additional parameters that may be included in the original URL when redirecting to the new URL. Preserving the query string is often useful for tracking purposes, like retaining analytics or advertising parameters, ensuring that useful data isn’t lost during redirection.
  5. Deploy the rule:
    Click Deploy to save and activate the redirect.

Now, whenever someone visits https://example.com/page-1, they will be redirected to https://example.com/page-2 with a 301 status code, indicating a permanent move.

You can efficiently manage traffic without touching your server configuration by setting up redirects via Cloudflare. It provides flexibility for using simple patterns or more complex URL structures.

Cloudflare offers essential tools to manage the performance of your website

Option 3: Create a 301 redirect the easy way with Yoast SEO

Our Yoast SEO Premium plugin offers you a helping hand when it comes to creating these redirects. Our built-in redirect manager assists you whenever you change the URL of a post, page, or any taxonomies that may result in a possible 404 if you don’t properly redirect visitors. In addition, we also offer you an interface to edit or remove these redirects at a later point in time. The plugin also tells you when you’re about to create a redirect that will result in a redirect loop. This looping is something you want to avoid at all costs.

Here’s how you can set up a 301 redirect using Yoast SEO Premium in WordPress:

  1. Access the Yoast SEO settings: Log into your WordPress admin area and navigate to the Yoast SEO section.
  2. Open the Redirect Manager: Go to the Redirects feature in Yoast SEO Premium.
  3. Add a new redirect: Follow the steps below to create a new rule.
    • In the Old URL field, enter /page-1 as the source path.
    • In the New URL field, enter the destination /page-2 as the complete new URL.
    • Choose a 301 (Moved Permanently) from the list of redirect types.
  4. Save the Redirect: Click Add redirect, and Yoast SEO will handle the redirection.

Yoast SEO Premium also offers an option to automatically redirect deleted content. When you delete a page or post, Yoast SEO prompts you to set up a redirect to avoid broken links. This ensures visitors and search engines won’t encounter 404 errors and are smoothly directed to a relevant page.

These features are part of Yoast SEO Premium, designed to make managing redirects straightforward without manually altering code or server settings. They keep your site user-friendly and help maintain SEO performance by preventing dead links.

Adding a redirect with Yoast SEO Premium is very easy

Conclusion

Understanding how to set up 301 redirects is essential for maintaining your website’s integrity and user experience. Whether you choose Cloudflare, Yoast SEO Premium, or the .htaccess method, each approach offers a simple solution to guide visitors to the right place, preventing 404 errors and keeping your SEO rankings intact. Smoothly transitioning traffic from old links to new ones enhances usability and search visibility. Choose the best method that suits your needs and keeps your website running smoothly.

Read more: How to properly delete pages from your site »

6 questions about redirects for SEO

A redirect happens when someone asks for a specific page but gets sent to a different page. Often, the site owner deleted the page and set up a redirect to send visitors and search engine crawlers to a relevant page — a much better approach than serving them annoying, user-experience-breaking 404 messages. Redirects play a big part in the lives of site owners, developers, and SEOs. So, let’s answer a couple of recurring questions about redirects for SEO.

1. Are redirects bad for SEO?

Are redirects bad for SEO? The answer is no; redirects are not inherently bad for SEO. However, it is crucial to implement them correctly to avoid potential issues. An improper implementation can lead to problems such as losing PageRank and traffic. Redirecting pages is necessary when making URL changes, as you want to preserve the hard work invested in building an audience and acquiring backlinks.

To ensure that redirects are implemented correctly and effectively, consider the following best practices:

  • Use the appropriate redirect type: The most commonly used redirect for permanent URL changes is the 301 redirect. This informs search engines that the original URL has permanently moved to a new location. By using a 301 redirect, you can maintain the ranking and relevance of the old URL and seamlessly redirect users and search engine crawlers to the new URL.
  • Update internal links: When you implement redirects, updating any internal links on your website that refer to the old URLs is important. This ensures visitors can navigate to the correct pages and search engines can properly index the new URLs.
  • Preserve user experience: Redirects should aim to provide a smooth user experience. Avoid excessive redirect chains, which can slow page load times and frustrate users. It’s also important to redirect users to relevant content that aligns with their intent. For example, if a page has been permanently removed, redirect users to a relevant alternative rather than a generic homepage.
  • Monitor and test redirects: Regularly monitor your redirects. Check for errors or issues, such as broken redirects or redirect loops. It’s also helpful to periodically test the redirects to ensure they function as expected.

2. Why should I redirect a URL?

By redirecting a changed URL, you send users and crawlers to a new URL, minimizing annoyance. Whenever you perform any maintenance on your site, you are taking stuff out. You could delete a post, change your URL structure, or move your site to a new domain. You must replace it, or visitors will land on those 404 pages.

If you make small changes, like deleting an outdated article, you can redirect that old URL with a 301 to a relevant new article or give it a 410 to say that you deleted it. Don’t delete stuff without a plan. And don’t redirect your URLs to random articles that don’t have anything to do with the article you’re deleting. Lastly, don’t 301 redirect all your 404s to your homepage!

Bigger projects need a URL migration strategy. For instance, moving to a new domain or changing the URL paths. In these cases, you should look at all your site’s URLs and map them to their future locations on the new domain. After determining what goes where you can start redirecting the URLs. Use the change of address tool in Google Search Console to notify Google of the changes.

3. What is a 301 redirect? And a 302 redirect?

A 301 redirect is a permanent redirect informing visitors and search engine crawlers that the requested URL has moved to a new destination permanently. It is the most commonly used redirect for permanent URL changes. When implementing a 301 redirect, you signal that the old URL is no longer in use and that the new URL should be accessed instead. It is important to note that with a 301 redirect, the old URL should not be used again in the future, as it signifies a permanent change.

On the other hand, a 302 redirect is a temporary redirect. This type of redirect is used to indicate that the requested content is temporarily unavailable at a specific address but will return at a later time. Unlike a 301 redirect, a 302 redirect suggests that the change is temporary and that the original URL may be used again.

You must consider the URL change’s nature when deciding which redirect to use. If the change is permanent and you have no intention of using the original URL again, a 301 redirect is appropriate. However, if the change is temporary and you plan on returning to the original URL, a 302 redirect should be used.

It is recommended to carefully consider the purpose and longevity of the URL change when selecting the appropriate redirect. If you are uncertain about which redirect you need, please read our article on which redirect to pick?

4. What’s an easy way to manage redirects in WordPress?

We might be biased, but we think the redirect manager in our Yoast SEO Premium WordPress plugin is incredibly helpful. We know that many people struggle to understand the concept of redirects and the work that goes into adding and managing them. That’s why one of the first things we wanted our WordPress SEO plugin to have was an easy-to-use redirect tool. I think we succeeded, but don’t take my word for it.

The redirect manager can help set up and manage redirects on your WordPress site. It’s an indispensable tool to keep your site fresh and healthy. We made it as easy as possible. Here’s what happens when you delete a post:

  • Move a post to the trash
  • A message pops up saying that you moved a post to the trash
  • Choose one of two options given by the redirects manager:
    • Redirect to another URL
    • Serve a 410 Content deleted header
  • If you pick redirect, a modal opens where you can enter the new URL for this particular post
  • Save, and you’re done!

So convenient, right? Here’s an insightful article called What does the redirect manager in Yoast SEO do, that answers that question. Or watch the video below!

5. What is a redirect checker?

A redirect checker is a tool to determine if a certain URL is redirected and to analyze the path it follows. You can use this information to find bottlenecks, like a redirect chain in which a URL is redirected many times, making it much harder for Google to crawl that URL — and giving users a less-than-stellar user experience. These chains often happen without you knowing it: if you delete a redirected page, you add another piece. So, you need to keep an eye on your redirects; a redirect checker is one of the tools to do that.

You can use one of the SEO suites, such as Sitebulb, Ahrefs or Screaming Frog to test your redirects and links. If you only need a quick check, you can also use a simpler tool like httpstatus.io to give you an insight into the life of a URL on your site. Another must-have tool is the Redirect Path extension for Chrome, made by Ayima.

6. Do I need to redirect HTTP to HTTPS?

Every site should use the HTTPS protocol, but be sure to redirect your HTTP traffic to HTTPS. You could get into trouble with Google if you make your site available on HTTP and HTTPS, so watch out for that. Google prefers HTTPS sites because these tend to be faster and more secure. Your visitors expect the extra security as well.

So, you need to set up a 301 redirect from HTTP to HTTPS. There are a couple of ways of doing this, and you must plan this to ensure everything goes as it should. First, the preferred way of doing this is at the server level. Find out what kind of server your site is running (NGINX, Apache, or something else) and the code needed to add to your server config file or .htaccess file. Your host will often have a guide to help you set up a redirect for HTTP to HTTPS on the server level. Some hosts have a simple setting to manage this in one go.

There are also WordPress plugins that can handle the HTTPS/SSL stuff for your site, but for this specific issue, we wouldn’t rely on a plugin, but manage your redirect at a server level. Don’t forget to let Google know of the changes in Search Console.

Redirects for SEO

There are loads of questions about redirects to answer. The redirect concept isn’t too hard to grasp if you think about it. Getting started with redirects isn’t that hard, either. The hard part of working with redirects is managing them. Where are all these redirects leading? What if something breaks? Can you find redirect chains or redirect loops? Can you shorten the paths? You can gain a lot from optimizing your redirects, so dive in and fix them. Do you have burning questions about redirects? Let us know in the comments!

Read more: How to properly delete a page from your site »

Coming up next!