Permanent Redirect 2.0 Released

Permalink Redirect 2.0 It has been a while -- you might have thought that I have abandoned that little WordPress plugin. It has been hanging at 0.8.x for a long time, but Fear Not! Let me introduce "Permalink Redirect Two Point Oh"! When the Web is about to enter into the era of 3.5, I have finally finished my first 2.0 product.

Download Permalink Redirect 2.0 (5.0kb ZIP)

Installation should be straight forward if you have installed it before. Unzip it, and then copy the PHP file ylsy_permalink_redirect.php to your WordPress' plugin directory. Activate it from your Plugin Manager page. Done!

So what is new in Permalink Redirect 2.0?

Only one new bug fix -- rewrite of the old permalink structure redirect handling.

Redirecting from the old permalink structure has been added quite a few ago, but having it working is a bit of hit and miss. How it worked was appending the extra rewrite rules generated from the old structure to a list of existing rules to be checked during WordPress' request parsing process, similar to Dean Lee's Permalinks Migration plugin. It is elegant, but does not always work.

It was ineffective due to the way WordPress processes through those rewrite rules. Some permalink structures are more aggressive than the others, as their regular expressions pretty much match everything (for example /%postname%/). Therefore some rules never get executed, and those old permalinks will never get detected and redirected.

So here is my less-elegant (or maybe call it hack'ish) solution. We will manually run through those old rules again after the main request parsing but before checking for redirection, only if a 404 Not Found is detected. It involves creating some of the main WP objects again and run them through alternate rewrite rules generated from old permalink structures. It will then try to redirect to the canonical URL if one of the old rules returns positive result, otherwise it will continue to process 404 Not Found.

It's quite a hack which exposes some of not so poetry code inside WordPress. At least it works (for me). It has been tested under WordPress 2.0.11, 2.5.1 and 2.6, but no guarantee that it will work for other future or past versions of WordPress. You ought to upgrade to the latest if you are using 2.1-2.3 anyway, or else... As it does a bit of work only when 404 occurs, it should not affect normal page viewing but 404 page handling will be a tad slower.

So, please download it and test whether it is working for you if you have a strange redirect issue with old permalink structures.

Now, why 2.0, especially when there has never been a 1.0? I will leave that to my next post -- WordPress plugins -- check before you upgrade automatically.