How To Add 301 Redirects To WordPress Via Plugin Or .htaccess File

If you’re ever planning to change your WordPress permalink structure, change the slug on a single post, or migrate your entire WordPress site to a new domain, then 301 redirects are going to be your best friend.

Web Hosting

301 redirects allow you to seamlessly redirect traffic from one URL to another without negatively affecting user experience for humans or SEO for robots.

In this post, I’ll show you how you can add 301 redirects to WordPress using a free plugin, as well as via your site’s .htaccess file. For the latter, I’ll also cover the redirect code snippets for all the scenarios that I mentioned in the first sentence.

WordPress 301 Redirects Explained In More Detail

301 redirects are a specific type of redirect that tell web browsers and search engines:

“The content that was originally at this location has permanently moved to this new location that I’m sending you to”

As part of that, the person (or search engine) will be automatically “redirected” to the new page.

So, say you have a 301 redirect like this:

  • Old: https://wplift.com/301-redirect
  • New: https://wplift.com/301-redirect-guide

Anyone who visits this URL:

https://wplift.com/301-redirect

Will be automatically taken straight to this URL (this usually happens so quickly that people don’t even notice):

learn wordpress wplift icon

Article continues after this block

You may also like these related articles

https://wplift.com/301-redirect-guide

This is important because it ensures:

  • Search engines know to replace the old page with the new page in the search engine rankings
  • You don’t lose traffic from existing traffic/links to your content

You can also use wildcards to create more complex redirects that affect multiple pages at once. For example, you could use 301 redirects to:

  • Redirect all traffic to your old permalink structure to the same post using the new permalink structure
  • Redirect all traffic to your old domain name to the same post on the new domain name

Basically, they come in pretty handy whenever you change any of the URLs on your site and want to preserve your original traffic and SEO rankings!

Next, I’ll show you how to add 301 redirects to WordPress using either a plugin or your site’s .htaccess file.

How To Use Redirection Plugin To Manage 301 Redirects

I’ll show you how to do all of this manually via .htaccess in the next section, but I want to lead with a free plugin that lets you manage 301 redirects.

Why?

Because for most WordPress users, it’s going to be a lot simpler and more convenient.

To manage 301 redirects right from your dashboard, you can use the free Redirection plugin.

Once you install and activate the plugin, go to Tools → Redirection.

To create a 301 redirect, all you do is:

  • Paste the original URL into the Source URL box
  • Paste the new URL that you want to send traffic to into the Target URL box
  • Click Add Redirect

how to use redirection plugin

Once you add some redirects, you’ll be able to edit, delete, or disable them from the same interface:

how to manage 301 redirects

If you’re tech-savvy, you can also use Regex to perform more complex redirects, like if you’re changing your permalink structure. This gets a little complicated, though. You can read this Regex explanation for help. And if you’re not sure, don’t be afraid to ask for expert help!

How To Add 301 Redirects To WordPress Via .htaccess File

Your WordPress site’s .htaccess file is a basic configuration file for your server. Through it, you can set up a variety of redirects on your site just by adding some simple code snippets.

The process generally goes like this:

  • Connect to your site via FTP or cPanel File Manager
  • Find the .htaccess file in the root directory
  • Add the code snippet that applies to the type of 301 redirect that you want to add

I’ll cover each step in more detail below.

Note – some WordPress hosts, like Kinsta, use NGINX to power their servers, which doesn’t support .htaccess files. So in some rare circumstances, you might need to talk to your host’s support for help setting up redirects.

Step 1: Connect To Your Server Via FTP Or cPanel File Manager

To get started, you can either use an FTP program to connect to your site via FTP (you can get your credentials from your host) or you can use cPanel’s built-in File Manager tool.

For this tutorial, I’m going to use cPanel File Manager because most hosts use cPanel and it’s the simplest method.

To get started, log in to your cPanel dashboard. Then, find the File Manager option under Files:

cpanel file manager

When you click it, choose the option for Document Root for and select the site you want to add the redirect to from the drop-down menu. Also, make sure the checkbox for Show Hidden Files (dotfiles) is checked:

how to access .htaccess file

And just like that, File Manager will open and you should see a copy of your site’s .htaccess file somewhere near the top:

finding the .htaccess file

Step 2: Back Up Your .htaccess File

Because your site’s .htaccess file affects your entire server, even a small typo can bring down your entire site (at least temporarily).

For that reason, you always want to back up the original .htaccess file before making any changes. That way, if you accidentally break something, you just need to upload the clean copy to get everything working again.

To back up your .htaccess file, just right-click it and select Download:

backup htaccess file

If you accidentally break anything while making the changes in the next step, you can just use that Upload button to upload the backup copy and get everything working again.

Step 3: Edit .htaccess File And Add Redirect Code Snippet

Once you have a backup copy of your .htaccess file safely downloaded on your computer, you’re ready to actually add the relevant redirect code.

To do that, right-click on the .htaccess file and choose the Edit option:

If you see a popup after clicking Edit, just hit Edit again on the popup to open the editor. Then, you should see something like this:

how to add 301 redirects in wordpress via .htaccess

Don’t worry if you see extra code in there – some plugins add their own code to the .htaccess file, so that’s perfectly normal.

Now, you just need to add the relevant 301 redirect code to the top of your .htaccess file.

So what code do you need? Here are 3 different situations:

The 301 Redirect Code You Need For Different Use Cases

How To Redirect A Single Post Or Page

To redirect a single piece of content, use this format:

Redirect 301 /old-url https://yourdomain.com/new-url

Where /old-url is the part of the URL that comes after the first “/”.

For example, to perform this redirect:

  • Old: https://wplift.com/301-redirect
  • New: https://wplift.com/301-redirect-guide

You would use this:

Redirect 301 /301-redirect https://wplift.com/301-redirect-guide

Here’s what this code would actually look like when placed in the .htaccess file:

example of 301 redirect code

How To Redirect Old Permalink Structure To New Permalink Structure

This one is a bit trickier because the exact code that you use depends on:

  • What your previous permalink structure was
  • What your new permalink structure is

If you’re moving to the Post name permalink structure, you can use this neat tool from Yoast to generate the code.

Otherwise, I recommend asking a developer for help because you’ll need to use Regex, which gets a bit more complicated.

How To Redirect An Entire Domain Name, If Changing Domains

If you’re moving your WordPress site to an entirely new domain, you can set up a 301 redirect on the old domain to automatically send all traffic to the same place on the new domain.

To do that, you need this code snippet:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourolddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yourolddomain.com [NC]
RewriteRule ^(.*)$ https://yournewdomain.com/$1 [L,R=301,NC]

Make sure to replace yourolddomain.com with your actual old domain and yournewdomain.com with your actual new domain name.

You Can Now Safely Change URLs On Your Site

You now have the knowledge of how to add 301 redirects to WordPress.

From now on, whenever you change any links on your site, you can set up a 301 redirect to ensure that you don’t lose any of your hard-earned traffic or search engine rankings.

Have any other questions about 301 redirects and WordPress? Leave a comment and we’ll try to help out!

Colin Newcomer

Colin Newcomer

Colin Newcomer is a freelance writer and long-time Internet marketer. He specializes in digital marketing, WordPress and B2B writing. He lives a life of danger, riding a scooter through the chaos of Hanoi. You can also follow his travel blog.

One thought on “How To Add 301 Redirects To WordPress Via Plugin Or .htaccess File

Comments are closed.