Redirection: An Easy Way to Handle 301 Redirects

Tutorial, WordPress

Since I’ve switched to my new design, I’ve also done quite a bit of cleanup work on the content side of things.  I pruned a lot of old articles that weren’t bringing in search traffic (and weren’t related to the site anymore), cleaned up a lot of the categories, and set my permalink structure to something that was a little easier to digest.

The problem, I noticed, came in when I changed the permalinks.  By doing so, any outside links coming in were immediately broken – meaning no search traffic was getting through.  This is, as you can imagine, a problem.

Luckily, I had already taken these things into account, and immediately installed one of my “must use” plugins – Redirection.

What does Redirection Do?

Basically, it serves as a switchboard between an old URL and a new URL.  You set up the relationship in the options panel and – when someone visits the old URL – they are automatically kicked over to the new URL with a 301 Redirect. Even better, when Google’s spiders crawl through and see that redirection, they’ll update their search results accordingly.

Real World Example of a 301 Redirect

Enter into your browser.  This was a site I had going for a while in 2014, but have since moved all of their blog posts and other content here.  UnderstandWP has Redirection running with a command to move *all* traffic here using a 301 redirect.  Since the permalink structures were the same, it was a clean move.

But sometimes that’s not always the case.

What if you change your permalinks and have 1000 articles?  Surely you don’t want to have to add in 1000 manual redirects.  Well, luckily, you have two options:

  1. Use excel and make a chart of all of your old URLs and new URLs (this can be done easily with a few cell formulas).  Then, upload the CSV into Redirection
  2. Use a “regular expression”

Regular Expressions (Regex)

A regular expression is a formula, at its most basic form.  It uses a combination of symbols, letters, and numbers to represent larger pieces of content.  The best thing to do is to take an example and break it down:

  • Source URL: /(\d*)/(\d*)/(\d*)/([A-Za-z0-9-]*)
  • Target URL: /$4

The source URL has four parts: in this case, it’s a year, month, date, and post-name. The \d* is short for “digits” – it means any number from 0-9.  The final piece is the post name.  That long variable string ([A-Za-z0-9-]*), in its most basic term, means “everything” – every letter, number, and symbol gets stored in a temporary value.

The Target URL then takes only the final piece of that puzzle – the post name – and redirects all incoming traffic, stripping out the dates and only using the post name.

In Redirection, it would look like this:

See that checked box on the right side? That’s important – that’s what tells the plugin to interpret the redirection as an expression.

Without going into the technical detail, because we could spend two or three posts talking about just Regex, know that:

  • Use (\d*) for numbers
  • Use ([A-Za-z0-9-]*) for mixed values (letters and numbers)
  • Count the number of variables you use, and use $ to call those in the Target URL ($4 calls the 4th variable, for example).

Have you ever changed your permalinks? Did you have any other ways to make sure traffic was going to the right place, even after the switch?  Leave us a note in the comments!