mattgadient.com

404 Redirect Reloaded plugin for WordPress (301/302 handling and 404 suggestions)

404 Redirect Reloaded is a fork of the original 404 Redirected by Robert Rolfe. The original plug-in really appealed to me, but it hadn’t been updated in a long time so I fixed a bunch of things that didn’t work (and other errors), and added a few features. Rather than selfishly keep it to myself, I’m offering it up here!

 

What is it?

Normally when a visitor tries to access a page on your site that doesn’t exist, they get a “404” page – most of the time these pages are fairly basic. Here’s what 404 Redirect Reloaded adds…

  1. It attempts to find posts/pages/tags/categories on your page that have a similar URL to what the visitor tried to reach.
  2. If it finds one that’s REALLY close (as in… it was probably a typo), it does an automatic 301 redirect to the “correct” page. It’s so quick and seamless that your visitor probably won’t even notice they’d typed the URL wrong.
  3. If it doesn’t find a page that’s really close, it will list the 5 closest matches it found, and display them on the 404 page.

 

Put another way:

Something like…

www.mysite.com/2014/02/01/i-took-the-dot-for-a-walk/
—> will be automatically redirected to the correct version —>
www.mysite.com/2014/01/01/i-took-the-dog-for-a-walk/

…or if the match isn’t that close….

404 Redirect Reloaded Example of Suggestions

 

A list with suggested alternatives shows up on the 404 page.

There are a number of things you’ve just seen above that can be changed/customized in the plugin options page:

  • at what % match to automatically redirect instead of providing a list (the default is at 90%).
  • Suggested Alternatives can be changed to say something else.
  • Instead of 5 alternatives, you can suggest more or less.
  • You can disable that “Generated using the 404 Redirect…” link.
  • …and more!

 

And there’s more!

I’ll start with the screenshots, and then add a little explanation below:

404-redirect-reloaded-captured 404-redirect-reloaded-redirects 404-redirect-reloaded-options 404-redirect-reloaded-options2 404-redirect-reloaded-options3 404-redirect-reloaded-custom 404-redirect-reloaded-hard-core-ignore 404-redirect-reloaded-edit-404-page404-redirect-reloaded-2014-theme

Every 404 is logged by the plugin so that you can see what posts/pages people are trying to access via a bad link. By default, most of this ends up in the “captured” tab – if you want to set up a redirect, just click “Edit” below the link, and you can use the dropdown box to select from any of your posts/pages. Alternately you can manually type in a redirect location.

The “redirects” tab is where you can look over redirects that have been set up. Remember that 404 Redirect Reloaded automatically sets up a redirect if it’s a close match – you might want to check here every once in awhile to make sure it’s matching this correctly! The default settings are pretty safe, but if you find that it’s getting the automatic redirects wrong, you can remove the items from here and adjust the settings in the Options tab.

The options tab is one of those places you’ll go into to tweak a few times until everything looks just right, and then you won’t ever visit again. All the options come with little explanations below.

 

One extra feature that was added is the “hard core ignore” feature. When running the original 404 Redirected plugin, one of my sites was under a bot-attack at the time, and I had a lot of attempts within /cgi-bin/ as well as a lot of attempts to inject various plugins that I didn’t have installed. This resulted in a couple thousand items in the “Captured” section and the Logs, which made it a royal pain to look for true broken incoming links that needed redirection. “Hard Core Ignore” lets you put in a part of a URL, and it will immediately remove every link that contains that piece of the URL from the log and the capture/redirect database. If the 404 Redirect Reloaded database tables are MyISAM, it’ll optimize those tables at the same time, removing the extra overhead. Note that this doesn’t actually affect the behaviour of your site – those bots will still hit the 404 page and will still get a recommended list (as would any visitors that tried links you “hard core ignored). It just wipes that particular information from the plugin and keeps it from being re-entered.

A few more features/fixes that were added vs the original:

  • When you first activate the plugin, you get a little help screen which includes the link to pop into your 404.php file. It will be available util you click “hide this message forever” at the bottom.
  • You can list up to 1000 entries at a time now (up from 25).
  • If you edit/trash/move/etc a link, it will now return you to your previous location in the list. Previously it sent you back to page 1 in the Redirects tab any time you did anything.
  • You shouldn’t end up in the situation where you can only see 1-2 links per page at a time with nothing displaying afterwards.
  • Your error log shouldn’t fill up with PHP warnings anymore, and if you have DEBUG enabled, it should be perfectly silent (let me know if you run into any cases where you get an error/warning due to the plugin!)
  • Borders are curved to help distinguish it from the original.
  • If you have something in “Redirects” that you want to remove without ignoring/trashing it, you can now move it to the “captured” section.
  • Instead of trying to force MyISAM, it will use whatever database engine you have set as the default. FULLTEXT indexes were removed to accommodate this.
  • A number of other things have been tweaked/changed.

 

Now for the bad news:

  • I’ve tested this on my sites, but I use pretty new versions of MySQL and PHP. There may be issues on older versions. You should back up before installing just in case.
  • I think I’ve caught most of the vulnerabilities in the original, but there are no guarantees – plugins like this are by their nature a little more risky because they deal with untrusted input which has to be sanitized (anyone can try to put anything in a URL which these types of plugins store in a database). Again, backups. And let me know if you come across any security issues that I missed.
  • You have to place that PHP code in your 404.php file manually. There aren’t any automatic hooks I’m aware of to get in there from a plugin. What’s worse, any time you update your theme it will overwrite the file so you’ll have to try to remember to insert that code again if you want the “suggested results” to display.
  • The “hard core ignore” may have some trouble trying to match certain special characters (which unfortunately are the ones you are likely to want to use when dealing with bots). I’ve worked around most of them but let me know if there are some that are giving you trouble (either not working, or acting as a wildcard).
  • Some of the code is a huge mess (sorry for anyone who tries to read it). I was often hacking away at something that wasn’t working correctly and didn’t go through to reorganize everything nicely afterwards.
  • It’s options are removed if you disable the plugin, which means if you temporarily disable it, you’ll have to set up any existing options you had again. The redirects/logs themselves will persist however.
  • It does add a little time to your website load. A max of just under 1ms is what I was seeing in testing, but I’m on a pretty quick server. If you’re on a typical GoDaddy/HostGator/etc shared server, you might see a few ms. Obviously, a page cache is a good idea. There are a number of areas I can tune when I get the time to try and shave this down some.

 

Download:

The first version is v0.0.1. This is a little intentional at this point, as I’d like everyone to treat it as an alpha/beta. Back up your site first, test it slowly/carefully, and don’t go throwing it on a live site willy-nilly. Please leave a comment if you run into any issues.

With that all out of the way, here it is:

404-redirect-reloaded-0.0.1.zip – 404 Redirect Reloaded v0.0.1 (Jan 13, 2014)
(initial release)

 

 

6 Comments

 | Leave a Comment
  1. hi, is this plugin still in alpha/beta? is it save to use it with latest php and wordpress 4.0?

    • I suppose I’d still call it alpha/beta (to encourage people to back up frequently, if nothing else).

      It still works in WordPress (up to version 4.1 now).

  2. So glad you did this. Using on latest WP as of 3/3/15 and works like a charm.

  3. Will you be updating this plugin further? It is now December 2015, and I’m hesitant to try it with the latest version of WP and/or if it won’t be maintained in the future. Thanks. The plugin sounds great with the mods you have made.

    • There aren’t any immediate plans for updates. Unfortunately, my work on plugins has taken a back seat to other stuff for some time now.

      I haven’t checked recently to see if any new 404 plugins have come about in recent times: it could be worth peaking through the WP plugin repo to see if there’s something out there you really like that fits your needs. If there isn’t, you’re of course free to take this one and modify/change it to suit your needs and even fork/redistribute it if you’d like (GPLv2).

  4. This is REALLY great you forked this plugin I used the original many years till it simply was not usable. Appears to work ok w WP 4.4 ๐Ÿ™‚ Thanks ๐Ÿ™‚

Leave a Comment

You can use an alias and fake email. However, if you choose to use a real email, "gravatars" are supported. You can check the privacy policy for more details.

To reduce spam, I manually approve all comments, so don't panic if your comment doesn't show up immediately.