How to Create a WordPress Website 301 Redirect Without A Plugin

Posted on March 5, 2016
WordPress 404 Error Fix Using 301 Redirect

If you have recently changed some of your WordPress website page slugs you are going to be disappointed to learn that your new page slugs are leading to 404 errors.

If you are interested in optimizing your website for search engines then you have to understand the importance of 301 redirects. Essentially in a nutshell a 301 redirect will tell any search engine that crawls your page…that it has moved permanently to a new home. Here’s an example. If you have a page called ‘blog’ it will default to the slug ‘blog’ in WordPress. So you would access the page directly by visiting www.yoursite.com/blog. One day you wake up and realize that using the slug ‘blog’ will get you nowhere with search engines. They will slip right past that slug when indexing informative pages for Google searchers. Yes…that’s the technical term for people who search using Google. Anyway, you decide you want to rename your blog slug to ‘ct-wordpress-website-tutorials’. It’s easy enough using the permalink meta box right under the title but simply changing the page name is no bueno. The next time Google refers someone to your blog or you try to use the original link: www.yoursite.com/blog will land squarely on a 404 Page Not Found error. To recap…404 bad, 301 good. Let’s get started.

First of all, there are countless plugins that will allow you to redirect a page. Some of them are pretty good such as Redirection which will automatically create a redirect for you when a post or page url changes. However, if you are like me you want to try to do this yourself rather than using a plugin which could stop being supported or conflict with another plugin or code snippet running on your WordPress site. One important note…if you are not very technical and worry about your site breaking when you have to edit code then I would highly suggest grabbing the free Redirection plugin which will allow you to accomplish your redirects without having to touch a line of code. With that being said, let’s take a look at how you would do this on your own.

In order to make these changes, you will need to access your .htaccess file on your server. You can do this by logging into your cPanel and then going into the file directory or more easily by grabbing a copy from your FTP client and then editing locally on your computer and reuploading when finished. No matter what you do…MAKE SURE YOU BACKUP YOUR ORIGINAL ACCESS FILE BEFORE YOU DO ANYTHING. Seriously, this file is very finicky and if you make a wrong change and don’t have your original you are going to pull your hair out and lose your voice screaming.

Okay…so you have your backup. Now, let’s open up the .htaccess file using your favorite code editor. My choice is Notepad++ which is free which is awesome. At the end of your .htaccess file you are going to include something like the following:

RewriteEngine On allows redirects on your server.
Redirect 301 denotes the type of redirect
/a-very-old-post/ is the old url that you changed and is now outputting a 404 page
http://yoursite.com/a-very-new-post/ is the new location of the page or post

It’s important to note the spacing within the structure of the redirect as this needs to be exact otherwise you will get an internal server error when you upload the file.

Hope this article helps but please make sure that you are comfortable editing the .htaccess file and that you have backed up the original file before you get started. If not there are lots of good redirection plugins out there that will help you to do this without touching a line of code.


Leave a Reply

Your email address will not be published. Required fields are marked *

 

Ready to Get Started? Call 203.516.0359