From time to time, you may need to do one or two URL redirections on your WordPress site. A URL redirect is a function that sends a user from one URL to another. A redirect basically sends a user to a page different from the one requested, perhaps because the original page is no longer available, or because you’ve moved things around.
Redirections can be done from URLs within your domain to to URLs within or outside your domain.
In my previous related article, I discussed how single author sites can redirect their WordPress author archive link to their about page (since an author archive is pretty much useless for single author blogs).
Redirections can be done in a number of different ways. One very popular method of doing redirects (on the popular Apache web server) involves the use of directives within the .htaccess file. Custom PHP code is also often used for redirections by WordPress developers.
This article however, will focus on providing some extra insights on using the famous WordPress Redirection plugin.
The Redirection Plugin
You can download and install the Redirection plugin from the WordPress plugin repo (link above) or you install and activate it from your WordPress dashboard. As the most popular redirection manager for WordPress, you can use it for managing redirections, keeping track of 404s, and hemming up loose ends on your site. The plugin has been around for over a decade, and as of this writing, has more than 1 million active installations.
Although this is a stable and feature-packed plugin, I found that some of the more complex redirections are not very intuitive. So I decided to write this article as a personal reference and to help others who may need to get up to speed really quick when working with this popular and useful tool.
We will look at what you really need to do your redirects, and explain these in a simple, clear manner.
There different types of redirects, but we will be talking about the 301 redirect which is arguably the most popular kind. 301 redirects are fully supported by this plugin.
In simple terms, a 301 redirect means that the page you’re looking for has been moved to another address (permanently). Think of it as going to an office you used to go to before, only to find a notice that they’ve moved. You go to their new address.
A typical use case for a 301 redirect would be when you changed the slug of a WordPress post. You still want to have users access that article via the old link. And the old link might even have been shared across social media or linked to from other websites. To prevent losing all the link juice flowing from the old post slug, you do a 301 redirect that takes them from the old link to the new one.
First Things First…
Activate the plugin after installation, and you’ll find its settings in the Tools >> Redirection link in the left sidebar menu of your dashboard. When you click Redirection you will be taken to the initial setup page.
Check the boxes there so the plugin can monitor permalink changes in posts and pages, keep a log of all redirects and 404 errors and store IP information for redirects and 404 errors. For the last one, that would depend on your site’s privacy and data collection policy.
Click Finish Setup, assuming the Rest API check after the preceding step is successful. Wait a few seconds while the plugin is setup and you should see the Finished! button appear. Click it.
The plugin has quite a few options. But for the most part, the options are self-explanatory. Just do a quick walk-through and get things set up the way you want.
After completing the initial setup, you will be taken to the Redirects tab on the main page of the plugin. Under the Add new redirection section, you’ll notice Source URL and Target URL text fields.
Source URL is the old URL, or the URL you want to point to a new one. Target URL is the URL to which you want to point the Source URL.
Let’s assume you want to redirect from https://ehikioya.com/author/someauthor/ to https://ehikioya.com/about/
https://ehikioya.com/author/someauthor/ becomes the Source URL, and https://ehikioya.com/about/ becomes the Target URL.
You’ll also notice the Group dropdown. You may want to group your redirects for the sake of keeping them organized. To create groups, head over to the Groups tab and create one. It will appear in the dropdown on the Redirects tab, and you can make use of it.
Note 1: Redirection strips the domain (in this case, https://ehikioya.com) from the Source URL. That’s ok! The plugin knows your site URL, so it will work.
Note 2: If the Target URL is also on your site, there’s no need to include the domain (in this case, https://ehikioya.com) in the Target URL. The plugin assumes the Target URL is on your site unless you specify a different domain. So, if you’re redirecting to a Target URL on the same site, just enter the part after the domain, starting with a / (in this case, /about/).
There is a gear icon that shows you more options when clicked. But for basic redirections, what we have discussed above should suffice. Of course, you can go ahead and play with the extra options as you like.
Welcome, Regular Expressions
I know some webmasters and even developers begin to freak out if they have to work with regular expressions. Don’t worry. We’re not taking a deep dive.
Just after the Source URL field, you may have noticed the URL Options/Regex dropdown. Selecting Regex gives you some more power when working with redirects.
Suppose your Source URL is https://ehikioya.com/old-subscription-page/ and your Target URL is https://ehikioya.com/new-subscription-page/ or just /new-subscription-page/
Some people will type your Source URL with the slash at the end. But others may not include the slash. If you just use the basic redirection we discussed in the previous section, your redirection will not work for people who did not include the trailing slash. To ensure that your redirection works for both situations, we have to apply a regular expression.
- Change your Source URL to https://ehikioya.com/old-subscription-page/?
- Notice the ? at the end
- Make sure that the Regex option is selected
- Leave your Target URL as https://ehikioya.com/new-subscription-page/
The “?” tells WordPress to redirect to the new URL whether it finds a trailing slash (/) in the Source URL or not.
Some Fairly Complex Regex Stuff
Suppose you recently moved things around. You have individual pages for your team members and the base page for the team was https://ehikioya.com/about/ (for example https://ehikioya.com/about/someauthor/). Now, things have changed and the base page for the team is now https://ehikioya.com/team/ (for example https://ehikioya.com/team/someauthor/). You have lots of team member pages and you want to redirect the old URLs to their corresponding slugs on the new base pages.
To accomplish the above, set your Source URL to https://ehikioya.com/about/(.*)
Be sure you’ve selected the Regex option. And set your Target URL to https://ehikioya.com/team/$1
How does this work? The Redirect plugin simply takes out /about/ and replaces it with /team/ and takes whatever characters may appear after /about/ in any URL to be redirected and puts it after /team/.
Here’s another similar scenario:
Say you used to have products on your website as well as a blog. All your products have /product/ as their base URL (for example, https://ehikioya.com/product/hand-crank-phone-charger/). Your blog sits on the root of your website (/).
Down the road, you deleted all your products for some reason but links to them are still littered everywhere around the Internet. You want to redirect all old product links to your blog homepage without having to do this manually for the hundreds of products you had.
To achieve this, just…
- Set your Source URL to https://ehikioya.com/product/(.*) or /product/(.*)
- Select the Regex option and
- Set you Target URL to https://ehikioya.com/ or simply /
Have fun playing with this great plugin. I’ll be glad to answer your questions in the comments section below.