Redirection is one of those things that isn’t important until you need it and then it knowing how to redirect in WordPress becomes one of the most important tools in your bag of digital tricks!
So why do you need to know about redirection? Well you might be missing out on a large amount of traffic, potential customers or even sales and not even know it.
How is it possible to lose traffic?
Well lets say you had a sales page that wasn’t doing great so you deleted it. Just before you deleted it one of the biggest sites in your niche or field of interest linked to your site. An unknown amount of traffic could be landing on a 404 page on your site (404 is the computer code for page not found). What a wasted opportunity for you and your visitors but don’t worry, redirection is here to save the day!
More than one way to redirect? There are a number of ways to redirect from one URL to another. The most basic way is a HTML redirect but that has more downsides than up sides to use at your own peril.
Redirect using Apache
An Apache redirect using a .htaccess file is one of the most powerful ways to perform a redirect but it does have a steep learning curve and if you do it wrong the results can be less than pleasant with the possibility of your entire site going offline until you fix your mistake.
A .htaccess redirect is best used when the redirection happens a lot, is dynamic or is just outside the of the control of your WordPress install. A simple but common example of a .htaccess redirect is redirecting all your visitors from your www subdomain to your normal domain for example www.JohnConleth.com redirected to JohnConleth.com.
The most common type of redirect is simply from one URL to another http://JohnConleth.com/my-test/ to http://JohnConleth.com/blog/
To perform a redirect like this you need to open the .htaccess file in the root folder of your WordPress install. If there is no file you might not be hosted by a server that supports .htaccess files.
This one line of code will redirect from one URL to another:
Redirect 301 /my-test /blog
Simply replace my URLs with your own, save the file and visit your site with the old URL. If the you get redirected to the new URL then you know the redirect has worked. Pretty much any kind of redirect can be achieved with a .htaccess file, once you know what kind of redirect you want and how to edit the .htaccess file it’s simply a matter of searching for a tutorial on how to do the specific kind of redirect you want to do.
Redirect using PHP
Another easy way to do a straight redirect is to create a PHP file. It’s not as hard as it sounds but won’t work for URLs that are not folder names. For example you’ll be able to redirect http://JohnConleth.com/my-test/ to http://JohnConleth.com/blog/ but not http://JohnConleth.com/index.html as it has an actual file name in the URL.
To create a redirect using PHP we simply create a folder with the name of the folder we want to redirect. We’ll use my-test as an example. Then create a new file names index.php and save it into the folder we just created.
Now add this code to the file and save it:
<?php header("Location: http://johnconleth.com/blog"); die(); ?>
If everything was done correctly when we visit http://JohnConleth.com/my-test/ it will redirect to http://JohnConelth.com/blog/
How to Redirect in WordPress with a Plugin
WordPress plugins are by far the easiest and most time efficient choice when it comes to redirecting WordPress content.
There are a large number of Redirection plugins available, to find the most popular you can visit http://wordpress.org/plugins or from within your WordPress install you can go to Plugins > Add new and search for the term redirect.
For me one of the best redirection plugins available for WordPress is Redirection. It’s an easy to use plugin that provides a large array of option should you need to use them. With Redirection it’s very simple to create a redirect. Just type in the old URL in the Source URL field and the new URL in the Target URL field and click Add Redirection. That’s it, your redirection is now ready to use!
How to know what needs to be redirected
Most of the time we know what we want to redirect but as I stated above there are often URLs that we should be redirecting that we don’t know or have forgotten about.
To help us find those URLs that we really should be redirecting we can use a number of tools. From within WordPress we can install any number of 404 plugins that will log what pages are missing. Make sure not to install a plugin that simply redirects all 404 pages to another page, this is something that search engines simply do not like because it results in lots of pages with duplicate content and badly written code can get stuck in a loop on your website because the number of possible pages is never ending (any random string of characters still shows a page on your site).
In my opinion the best option is to use the 404 option in the Redirection plugin, it keeps track of missing pages and gives you the option to add the URLs as a redirect to another URL – neat huh?
An alternative would be to use Google webmaster tools or Google Analytics to help you locate missing pages and then redirect them using any of the methods outlined above.
I hope this tutorial on how to redirect in WordPress has given you a better understanding of how redirection works and why you need to use it. If you have any tips or questions just leave me a comment below.