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.

Category: Technology | Thu, 17 July 2008 11:28 pm

Comments

1.
Avatar for wordy
Posted by wordy on Sun, 20 July 2008 8:16 pm

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


2.
Avatar for scotty
Posted by scotty on Sun, 20 July 2008 8:19 pm

@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.


3.
Avatar for wordy
Posted by wordy on Tue, 22 July 2008 11:24 am

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!


4.
Avatar for gwc
Posted by gwc on Thu, 24 July 2008 1:47 am

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?


5.
Avatar for scotty
Posted by scotty on Thu, 24 July 2008 7:33 am

@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.


6.
Avatar for John
Posted by John on Tue, 29 July 2008 9:36 am

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


7.
Avatar for scotty
Posted by scotty on Tue, 29 July 2008 10:06 am

@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.


8.
Avatar for Peter Kellner
Posted by Peter Kellner on Sun, 3 August 2008 7:57 am

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


9.
Avatar for clickfire
Posted by clickfire on Sun, 24 August 2008 4:10 am

Scott, I have it running on a WordPress 2.6.1 installation and it’s working fine. Thanks for the great plugin.


Avatar for digyourlove
Posted by digyourlove on Fri, 17 October 2008 3:02 pm

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.)


Avatar for V.K. Rajagopalan
Posted by V.K. Rajagopalan on Sun, 16 November 2008 7:03 pm

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


Avatar for scotty
Posted by scotty on Tue, 18 November 2008 10:14 am

Sorry this plugin has never been tested on WP MU…


Avatar for Howard
Posted by Howard on Mon, 8 December 2008 4:03 am

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 !


Avatar for bread
Posted by bread on Tue, 16 December 2008 10:45 am

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,


Avatar for Nemo
Posted by Nemo on Mon, 22 December 2008 2:44 pm

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.


Avatar for bread
Posted by bread on Sun, 28 December 2008 5:07 pm

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,


Avatar for clickfire
Posted by clickfire on Sun, 28 December 2008 5:22 pm

The plugin is working fine for me after upgrading to 2.7.


Avatar for bread
Posted by bread on Tue, 30 December 2008 8:14 pm

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.