Permanent Redirect 2.0 Released
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.
Comments
@wordy — it is a bit different. What WordPress does is to redirect from old to new when your pagename gets changed as WordPress actually kept your old name. It is done on a per-post basis.
What this plugin does, however, is to redirect when your entire permalink structure has changed. For example if your current structure is
/%year%/%month%/%postname%/
and would like to change to
/%category%/%postname%/
This plugin will ensure the visitors going to the old URL will get redirected to the new.
Ah ,thanks for explaining ,i got a bit confused. So if i just want to edit some of my single post titles i don’t need this plugin right, wp will do the job, right? I don’t have to change my permalink structure, i actually chosen a custom one since day one.
Thanks again!
I’m a novice so forgive dumb question. Does it take care of 404 and 301 out of the box? Or do you must know a page is broke and enter in Options pairs? Also occasion site exceeds Host’s memory cap and 500 error shows to user. But two seconds later would be fine. Can use yours to have redirect to a page if 500 error?
@gwc — it only takes care of 404 if you instruct the web server to let WordPress to handle 404 (via .htaccess file). When 404 is detected, it goes through a list of rules to try to figure out what the correct address is, and returns back 301 redirect instead.
As of 500 error handling, it occurs when WordPress (or PHP) is having issue so my plugin is not even invoked, and it is no way from my plugin to correct the issue.
Hello,
I have seen a lot of people recommending this plugin, but I am not sure I understand what it does. Could you please let me know if I need to use this plugin? Here is my setup.
I have upgraded the blog to the latest version (2.6). My permalink structure has always been /%postname%/ and my .htaccess file is set to strip www from the url.
I have not changed any post slugs in my published posts and I am not planning to in the future. Do I need to use this plugin?
Thanks,
John
@John — you probably don’t. WordPress 2.5 has already included the core functionality of this plugin (redirecting to the canonical URL) so what’s left is being able to fix permalink structure changes and other fancy redirects, which you probably don’t need.
somehow, one of my wp upgrades (I’m at 2.6 now) must have changed how my blog was referenced. I had an old reference as http://peterkellner.net/archives/2006/01/08/23/ which no longer works. The article is now at http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/. This is the only article I’m worried about.
My question is, does this plugin help with this problem? If not, can you point me at a way to solve my problem?
THanks
Scott, I have it running on a WordPress 2.6.1 installation and it’s working fine. Thanks for the great plugin.
Scott,I’m first enter your site.I’m just a freshman in Wordpress.:-P
I’m running on a Wordpress 2.6.2 now,but in wp-admin page ,I choose “setting”->”Permalinks”->”http://127.0.0.1/wordpress/2008/10/sample-post/”->”Save changes”.
So,I think the url will change in the whole page,but it just work in my index page….for other it shows “Object not found!” ,so why?
Please send me a e-mail…(could you use chinese write to me…thanks.)
Hi Scotty,
I have been using your plugin v0.8.x for a long time now. And, it has been working very well for me.
But, now I am in the process of customizing a new blog, http://www.honorablereviews.com. This is based on WordPress MU v2.6.3
In this MU, I am not able to activate your plugin.
Is your plugin MU compatible? If I upgrade to v2.0, will it work under MU?
Please advice.
Thanks
Raj
Hi Scotty !
I’ve used your plugin when changing permalink structure in the past and it worked great, but now I did another change that is not working.
I was using /%postname%/ structure, and changed to /customfrase/%postname%/ and the site is loosing all it’s traffic, old structure gets 404 now, I added the old structure to “Old Permalink Structures” area of the plugin since it wasn’t redirecting, but still nothing.
Any ideas ?
What should be the correct structure in “Path pairs to redirect from and to”
maybe that will work.
Thanks !
Hi, Scott,
It seems that the Permanent Redirect 2.0 Plug in is conflicting with Wordpress 2.7. Could you test it, please and update accordingly, please?
Thanks,
I have a question about your plugin. I am also looking to install the “Paged Comments” plugin from http://www.keyvan.net/ and the question I had is if this will work with that plugin. I tried another permalink redirect but if I use the paged comments plugin it does not allow me to go to a different page of the comment. It is frozen on that one page, and will not allow me to go to a different page of the comments, it redirects to the original post url without the extra url for paged comments…. if that made sense.
When this plugin is activated, it causes following error messages with wordpress 2.7.
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/breadncu/public_html/kblog/wp-includes/classes.php on line 210
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/breadncu/public_html/kblog/wp-includes/classes.php on line 211
If you have a time, would you look at the issue, please? Thanks,
BTW, I left blank in both ‘path to be skipped’ and ‘Path pairs to redirect from and to’ Also, I put followings in ‘Old Permalink Structures’
/?p=%post_id%
/archives/%post_id%
/%year%/%monthnum%/%day%
/%year%/%monthnum%/%day%/%hour%-%minute%
And, I think the first line causes problem and the last one does not seem to work. Would you check if it works in your place?
Add a comment
Gravatar is used. Email address is required but will not be displayed. Please keep your comment on topic. No spamming and/or bad language. First time poster will be moderated. Scott reserves the right to delete/edit your comments.

Hello, thanks for updating this plugin.
I have a question however. I was doing some testing today with permalinks before adding your plugin.I have noticed that if i change the permalink name WP will redirect from old to new one anyway.
I basically just went to edit some of my permalinks with better titles, if WP takes care of this issue do i still need your plugin?
Thank you very much