There are times, hopefully rare occasions, when a WordPress post that has already been published needs to be taken down, or replaced by another that is totally different. Redirects are there to help in those moments.
A URL redirect takes traffic pointed at one address and redirects it to another. Over time, search engines that have indexed the old address will point to the new one. We want our redirect rule to work for web traffic coming from anywhere the old link was distributed – on social media, for example. And that’s where redirects get slightly more complicated. A URL can have slightly different versions, depending on information that automatically gets added to the end of it.
Here’s how to handle redirects using a tried and true WordPress plugin – called Redirection.
After installing and activating the plugin, find the Redirect option under the Tools menu:
In the plugin’s screen, you’ll see a list ready to populate with redirects and a set of menu tabs.
Redirects you have set up will be listed here, with the options to edit, delete, or disable them.
The “Log” tab holds a helpful short-term tracker of successful hits to redirected pages, letting you verify they are working. The 404’s tab shows broken links on the site people are hitting (often due to user error or random searches or crawler activity) that you might want to set up a redirect for.
To set up a new redirect, hit the Add New button at the top. This will bring up an editing box to add the redirect source path and destination path, or target. First, the old page address you want to redirect traffic away from and second, the one which you want to redirect traffic towards.
If you had a great deal of redirects to do, you would want to organize them into a group – for just a few, it’s fine to use the default group, ‘redirects.’ The Regex option is something I’ll return to in a moment – first, for a simple redirect of an exact pattern match, you would leave it unchecked.
That would look something like this:
The first field expects a relative URL – leaving out the https://example.com part because these are always coming from our site. The second field expects a full URL, because these redirects can send the user anywhere else on our site or to any other website.
The above would work for all cases of people visiting exactly this: https://example.com/2020/old-page
We could hit “Add Redirect” and that part is done.
Now, what if this story already got distributed on social media? Links coming in would look like this instead if people are clicking from Facebook: https://example.com/2020/old-page?fbclid=IwAR3UkxyeuzzMEFPw_AS3WKgqRNfG_srJXpoFr1GxjZF3zSRueB0bJdS3Bhs
So, we need one more redirect to handle that.
The source URL needs to now include all patterns that have anything after the page link itself. For this kind of match, we need to check the “Regex” option because this is a “regular expression” – special syntax that lets us match advanced patterns of text characters. (You need an intro to regex, try here.)
The ‘match any and all characters after’ pattern is this (.*), so we add that to the page link to get /2020/old-page(.*).
Now, we have a complete direct for the old page to the new one.
Test by visiting yourself, and once traffic starts hitting and getting redirected, you will be able to see it in the Log tab.
For more, visit the Redirection plugin’s detailed but readable support and how-to page.
Test by visiting yourself in a fresh web browser tab, and you should skip right past the old page and land on the new one.
Once traffic starts hitting the old link and getting redirected, you will be able to see that activity in the Log tab. In the Redirects tab, you can edit, disable or delete redirect rules you have set up.
For more, visit the Redirection plugin’s detailed but readable support and how-to page.