Dougal Campbell's geek ramblings

WordPress, web development, and world domination.


I mentioned earlier that I have converted my site to WordPress, and set up link redirection for the old links. There’s some discussion going on over at Alex’s site about this subject as well. I figured I’d put up some notes about what I did.

First of all, for a couple of static links, like for my RSS files, I just added some redirect directives to my .htaccess file, like so:

# redirect the old MyPHPBlog RSS locations to the new WordPress ones:
RedirectPermanent /myphpblog/rss.php
RedirectPermanent /myphpblog/rss2.php

That part was easy enough. But the hard part is redirecting old permalinks and comment links. Both systems use querystring parameters, and they use different variable names and formats, plus the MPB stuff was all under a subdirectory:

MyPHPBlog Permalink
WordPress Permalink
MyPHPBlog Comment
WordPress Comment

The first thing that comes to mind is to use Apache’s mod_rewrite functionality. However, as others have noted, mod_rewrite doesn’t have access to the query string. My URI rewriting needs were also more complicated than Matt’s, so I decided to borrow some ideas from’s url shortcuts.

I do this by using a custom 404 error handler in my .htaccess:

ErrorDocument 404 /redirector.php

Then, I wrote a redirector program in PHP that gets the name of the requested file and the querystring variables, and sends the browser a permanent redirect, or a real 404, as necessary. It should be fairly easy for me to extend the redirector as necessary to accomodate other URLs, if needed.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in Tech and tagged , , . Bookmark the permalink.

2 Responses to Redirection

  1. Chris says:

    I came across your post via google. And I have a question..

    Is witched from wordpress to movabletype and the probelm is I need to redirect the old urls ( to the new urls ( some of the links.

    I’d like to rewrite the wp urls to ( so I can redirect them, but I can’t figure out how.

    Do you know of a place where I can find answers?

  2. Pingback: #WordPress » dougal

Leave a Reply

%d bloggers like this: