Search
Close this search box.

Redirecting Old WordPress Content – WPQuickies

In this lunchtime #WPQuickies, I’m looking at how to redirect old or moved WordPress content.

Redirecting Old WordPress Content – #WPQuickies webinar

What Is Content Redirection?

A redirect is a way for your web server to tell a visitors web browser that the page they have tried to access now has a different location.

When I say location, I mean the URL of single web pages.

Each URL is a unique location to get to a web page on the interwebs.

It’s quite common for website owners to change the location of web pages after a site redesign, a website content audit or to get better SEO results.

Why Redirect Content?

If you move web pages around, of course you will want your site visitors to still be able to access them at the new location.

But, mostly, redirects are in place to tell Google to update its index and for your site not to loose any SEO rankings the old content already had.

You really want to avoid Google picking up on 404 not found errors. 

That will damage your overall SEO score as well as losing credibility with your audience.

Different Type of Redirects

There are seven types of redirect codes a web browser understands:

  • 301 Moved Permanently
  • 302 Found (moved temporarily – don’t cache the final URL)
  • 303 Other (like 302 but NEVER cache)
  • 304 Not modified (no need to retransmit resource)
  • 305 Use Proxy (resource only available via a proxy)
  • 307 Temporary Redirect (most search engines treat like 302 – used for A/B testing – method can’t change: Post/Get/Put/Patch/Delete)
  • 308 Permanent Redirect (like 301 – method can’t change: Post/Get/Put/Patch/Delete)

Most website owners will only need to use 301 redirects and that’s what we’ll focus on in this talk.

Redirecting Moved WordPress Content

I’ll take a quick look at some methods of redirecting your content which should cover most website owners needs.

Using a Redirect Plugin

I would recommend using the Redirection plugin.

It is simple and has an option to record all your 404 (not found) errors so you can see which pages people are trying to access so you can set up a 301 redirection to the new location, as well as being able to create manual 301 redirections.

Using a plugin for 301 content redirection means the website owner doesn’t have to muck around with any web server configuration files or settings.

This plugin works with Nginx as well as Apache which are the two most widely used web servers.

301 content redirection example using the Redirection plugin

The above example uses a simple plain-text redirection and redirects the URL “/chicken-wings” to the URL “/super-hot-finger-licking-chicken-wings”.

Because the redirections start with the slash character / they are “relative” to the main domain name for the website.

If you were directing content to a new domain name, you would enter the full URL including https:// into the second target URL field.

e.g. “/chicken-wings” to https://mynewdomain.com/chicken-wings

This is fine for redirects on a per-page basis, but what about hierarchical content?

For this you are going to have to learn a little bit about regular expressions.

301 Content Redirection With Regular Expresions

Regular expressions are a set of rules that allow you to define parts of, in this case a URL, and use them in the redirection.

For example, to redirect all sub pages of chicken-wings I would use the following regular expression:

Source URL: ^/chicken-wings/(.*)

Target URL: /super-hot-finger-licking-chicken-wings/($1)

Example of adding a new regular expression 301 redirction in the redirection plugin

The “(.*)” part allows us to match every character after the last slash in the source URL, in this case all sub-pages.

The “($1)” part in the target URL tells us to use all the stuff from in the first brackets from the source URL and output it right here at the end of the target URL.

Example showing a new regular expression 301 redirction rule in the redirection plugin

Regular expressions can take a while to learn but you can Google for your particular use case and 99% of the time somebody will already have a solution for it, so just copy and paste source and target URLs.

Redirecting Manually

If you really don’t want to use a plugin, if you use Apache then you’ll have to add your rewrite codes in your .htaccess file.

Here is the chicken-wings 301 redirection example for Apache:

<IfModule mod_rewrite.c>
   RewriteRule ^/chicken-wings/(.*)$ /super-hot-finger-licking-chicken-wings/$1 [R=301,L]
</IfModule>

If you are using Nginx, you’ll have to update the server block for your webs server in the nginx configuration folder.

Here is the chicken-wings 301 redirection example for Nginx:

server {
   server_name mydomain.com
   rewrite ^/chicken-wings/(.*)$ /super-hot-finger-licking-chicken-wings/$1 redirect;
}

Redirecting Removed/Deleted Content

Sometimes pages on your site are just generating rubbish SEO and aren’t relevant to your site anymore.

In this case, don’t feel bad about just removing the content – the SEO was rubbish anyway.

However, sometimes you may have to retire content that is still getting a good bit of SEO goodness, for example contained within PDF files, but you don’t really want to lose the SEO from it.

Redirecting PDF’s Using 301 Redirects

PDF’s have been indexed by Google since 2006 so removing them could damage your SEO back-linking, leading to something called “link rot”.

In this case, I would recommend that you refactor (rewrite) the content to give it a more relevant spin to your site.

Create a new post or page for the content that you are retiring but make sure it still relates to the old content in some way, otherwise you will lose the Google SEO love.

When I refactor old content from large posts, I like to split it up into a whole bunch of smaller topics that I can link to from the main replacement post, which you can use as a cornerstone article.

Redirect your retired content URL to the new cornerstone article URL.

Redirecting PDF’s Using PHP

I’ve come across some web servers that aren’t Apache or Nginx and even the Redirection plugin doesn’t work with PDF files.

There is another method of redirecting PFD’s using a naming trick and four lines of PHP code. Here’s the trick:

Step 1 – Rename Your Old PDF File

We’re going to trick the server into redirecting the old PDF file but we can’t do anything with the physical file so rename it to myfile-old.pdf or just remove it from the server.

Step 2 – Create A New Folder

Create a new folder which is the exact name of the old PDF file.

For example if your old PDF file was called “2019-products-list.pdf”, create a directory in the same location called “2019-products-list.pdf”.

Yes, folders can have periods “.” in them.

Step 3 – Create An Index File

Inside your newly created folder, create a file called “index.php”.

The index.php file is the first file that a server will automatically open when the URL being visited is a directory.

Step 4 – Some PHP Code

Lastly, open the index.php file and add the following four lines of code.

<?
php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: https://www.yoursite.com/the-url-to-your-new-post-or-page" );
?>

Remember, of course, to change the https link to the link of your new post or page that you are redirecting the old PDF file to.

Conclusion

  • Use redirects to keep SEO goodness
  • Redirect after site restructure
  • Use a plugin – it’s easier
  • Repurpose deleted content into multiple new articles
    • redirect to a main cornerstone article

Join me every Thursday at 1 pm AEST for some more WPQuickies.

Suggest a #WPQuickies Topic

If you have an WordPress topic you’d like to see explained in 30 mins or under, fill out the form below.

https://forms.gle/mMWCNd3L2cyDFBA57

Was this article helpful?
YesNo