Search
Close this search box.

WP Buffs Blog |

How to Add 301 Redirects to WordPress via htaccess

How to Add 301 Redirects to WordPress via htaccess

Do you know what happens if you ever change the URL of a post or page on your WordPress site?

Nothing good, that’s what! Search engines like Google won’t be able to recognize that the page moved and any visitors who try to go to the original URL will get a 404 error.

Uh-oh

All those links and traffic you built to the original page will just…disappear. But it doesn’t have to be that way.

While keeping your website 99.9% secure and achieving loading times under 1 second are important, making sure your websites redirects are in order and your visitors have a great experience is paramount.

If you implement and set something called a 301 redirect, both search engines and humans will be automatically taken to the new URL if they try to access the old webpage. That means you get to change the link AND keep your traffic and search rankings. That’s a win-win!

Let’s take a deep dive into 301 redirects, adding them to WordPress via the .htaccess file (or a helpful plugin), and redirecting posts and pages on a WordPress website.

Our team at WP Buffs helps website owners, agency partners, and freelancer partners add 301 redirects to WordPress. Whether you need us to manage 1 website or support 1000 client sites, we’ve got your back.

What is a 301 Redirect?

Ok, I’ll try to keep this explanation human-friendly and refrain from slinging terms like “HTTP Status Code” at you.

There are many different types of redirects, but 301 is the most useful for the majority of WordPress sites. 301 redirects tell browsers and search engine robots that the page has moved permanently. Knowing the change is permanent isn’t especially important for humans, but it’s essential for search engines.

By indicating the page has permanently moved, the search engines know that they should rank the new page in approximately the same search engine ranking position as the old page.

Basically, if you want to try to keep your rankings when you change a page’s URL, you should stick to 301 redirects.

When Should You Use a 301 Redirect?

If you’re an average WordPress user, here are some of the scenarios where you’ll likely want to use 301 redirects:

  • You change the URL of a single post or page. If you change the URL of a post or page, you need to add a 301 redirect so that any internal or external links pointed to the old URL will be redirected to the new one.
  • You want to consolidate multiple posts into one. If you have, say, three different posts on a similar topic, a good strategy can be to consolidate all these posts into a single, stronger one. If you choose to do this, you can 301 redirect all three old posts to the new and improved one.
  • You change your domain name. If you change your domain name (while keeping the same content), you’ll definitely want to 301 redirect your old WordPress install to the new one.

Now that you know the what, when, and why, let’s get into the how! Here’s how you can add 301 redirects to WordPress with your .htaccess file.

How to Add a 301 Redirect to WordPress With .htaccess

Your .htaccess file is basically the configuration file for your web hosting server. To add 301 redirects using the .htaccess file, you need to:

  1. Actually find and download the .htaccess file from your server (requires an FTP program)
  2. Back up your .htaccess file (IMPORTANT)
  3. Add your redirects and upload the new version of your .htaccess file

Here’s how:

Step 1: Find Your .htaccess File

To find the .htaccess file for your WordPress site, you’ll need to connect to your web server via FTP. If you’re not sure exactly how to do this, your hosting provider should be able to help.

Your .htaccess file will be in the root folder of your WordPress site. This is the same folder that includes files like wp-config.php and folders like wp-admin and wp-content. For example, here’s what that looks like on my site:

htaccess

Once you find it, download that file to your computer.

Step 2: Back Up Your .htaccess File

This step is incredibly important. Like I said, .htaccess is the configuration file for your whole server, so you don’t want to make a mistake. That’s why you should always keep a copy of your original .htaccess file. That way, if anything goes wrong you can just re-upload the original file.

So, before making the changes in the next section, make a copy of the .htaccess file you downloaded from your site and keep the original file safe, secure, and unedited.

Step 3: Add Necessary 301 Redirects to Your .htaccess File

After you’ve made a copy of your original file (just wanted to remind you one more time!), you’re ready to add your redirects.

Start by opening the .htaccess file. If you’ve never opened a .htaccess file before, you’ll probably need to right click, choose Open With and select Notepad. Here’s what that looks like in Windows 10:

Notepad in Windows 10

If you’re using pretty permalinks, you should see something like this:

opened htaccess file

This is the basic structure WordPress added when you set your permalinks. Some plugins, especially caching plugins, may have also added some rules, so there’s no reason to panic if you see more code than the example above.

To add redirects, you should add the relevant code (examples below!) to this .htaccess file.

To redirect a single post or page, add the following short snippet for each post or page you want to redirect:

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

Where /old-url is only the part that comes after yourdomain.com. For the new URL, you should input the full URL, though.

For example, to 301 redirect “www.wpbuffs.com/301-post” to “www.wpbuffs.com/how-to-redirect”, you would add this code:

Redirect 301 /301-post https://wpbuffs.com/how-to-redirect

To redirect an entire website to a new domain, add the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]

Where olddomain.com is your original domain name and newdomain.com is your new domain name. This type of redirect will preserve your link structure, so “olddomain.com/about” will redirect to “newdomain.com/about”.

If you don’t want to dig into your .htaccess file, you can also add 301 redirects with a WordPress plugin called Simple 301 Redirects.

How to Add 301 Redirects to WordPress with Simple 301 Redirects

True to its name, Simple 301 Redirects provides an easy way to add a variety of 301 redirects to WordPress. It’s also 100% free, which is always nice!

To get started, install the plugin and activate it. You can access your new redirect panel by going to Settings > 301 Redirects:

301-redirect-wordpress-htaccess-5

To redirect a single page or post, all you need to do is enter the ending part of the original URL on the left and the entire new URL on the right. Here’s what that looks like for the WPBuffs example I used earlier:

301-redirect-wordpress-htaccess-4

You can also redirect posts or pages to an external domain if you want. Just enter the exact external URL in the Destination box.

If you check the Use Wildcards? box, you can do some more advanced redirects. For example, if you use category names in your permalinks, you could redirect every post in a category to a new URL by entering something like:

301-redirect-wordpress-htaccess-6

The asterisk is essentially a placeholder for any possible text that comes after the category name you enter.

Wrapping Things Up

Whenever you change a link (or links) on your WordPress site, you need to add a 301 redirect if you want search engines and humans to be able to easily find your new page.

It doesn’t matter whether you add 301 redirects manually via .htaccess or via the Simple 301 Redirects plugin. The important thing is just that you add them. They don’t take much time to add and they ensure that none of your previous marketing efforts go to waste!

Want to give your feedback or join the conversation? Add your comments 🐦 on Twitter.

SaveSave

SaveSave

If you enjoyed this article, then you’ll really enjoy the 24/7 WordPress website management and support services WP Buffs’ has to offer! Partner with the team that offers every aspect of premium WordPress support services.

From speed optimization services, to unlimited website edits, security, 24/7 support, or even white-label site management for agencies and freelancers, our expert engineers have your back. Bring us in as part of your team to make your site Bufftastic! Check out our plans

Curious about what we do?

Honed and proven strategies we've used successfully 500+ times to help you sell your first care plans. Action steps you can implement in minutes.

No thanks, I can already sell as many care plans as I want.
How to Sell Your Very First Care Plans Cover

WP Buffs, LLC is committed to protecting and respecting your privacy, and we’ll only use your personal information to administer your account and to provide the products and services you requested from us. From time to time, we would like to contact you about our products and services, as well as other content that may be of interest to you. If you consent to us contacting you for this purpose, please enter your name and email address above.

 

You can unsubscribe from these communications at any time. For more information on how to unsubscribe, our privacy practices, and how we are committed to protecting and respecting your privacy, please review our Privacy Policy.

By clicking submit above, you consent to allow WP Buffs, LLC to store and process the personal information submitted above to provide you the content requested.

Finally, an email list that helps make WordPress simple and effective for you.

Speed & security optimization tips and detailed how-to guides with advice you can implement today.

No thanks, I already know everything about WordPress.
Speed checklist eBook cover

WP Buffs, LLC is committed to protecting and respecting your privacy, and we’ll only use your personal information to administer your account and to provide the products and services you requested from us. From time to time, we would like to contact you about our products and services, as well as other content that may be of interest to you. If you consent to us contacting you for this purpose, please enter your name and email address above.

 

You can unsubscribe from these communications at any time. For more information on how to unsubscribe, our privacy practices, and how we are committed to protecting and respecting your privacy, please review our Privacy Policy. By clicking submit above, you consent to allow WP Buffs, LLC to store and process the personal information submitted above to provide you the content requested.

Case study eBook cover (Rigorous Digital)
Case study eBook cover (MEP Publishing)
How to Sell Your Very First Care Plans Cover

Finally, get your website 99.9999% secure and loading in under 1 second.

Our free eBooks and easy-to-follow checklists will have your website fully optimized in just a few hours.

No thanks, my website is as fast and secure as I want it.

WP Buffs, LLC is committed to protecting and respecting your privacy, and we’ll only use your personal information to administer your account and to provide the products and services you requested from us. From time to time, we would like to contact you about our products and services, as well as other content that may be of interest to you. If you consent to us contacting you for this purpose, please enter your name and email address above.

You can unsubscribe from these communications at any time. For more information on how to unsubscribe, our privacy practices, and how we are committed to protecting and respecting your privacy, please review our Privacy Policy. By clicking submit above, you consent to allow WP Buffs, LLC to store and process the personal information submitted above to provide you the content requested.

How to Sell Your Very First Care Plans Cover

Read about how we increased Rigorous Digital's profit margin by 23% and helped remove all website issues for MEP Publishers and their 3 complex websites.

Case study eBook cover (MEP Publishing)
No thanks, I don't need more profit and I can tackle all my WordPress issues myself.
Case study eBook cover (Rigorous Digital)

WP Buffs, LLC is committed to protecting and respecting your privacy, and we’ll only use your personal information to administer your account and to provide the products and services you requested from us. From time to time, we would like to contact you about our products and services, as well as other content that may be of interest to you. If you consent to us contacting you for this purpose, please enter your name and email address above.

 

You can unsubscribe from these communications at any time. For more information on how to unsubscribe, our privacy practices, and how we are committed to protecting and respecting your privacy, please review our Privacy Policy.

By clicking submit above, you consent to allow WP Buffs, LLC to store and process the personal information submitted above to provide you the content requested.