Redirecting Old WordPress Articles to SubText Articles After Migrating Blogs
Posted by Keith Elder | Posted in Programming | Posted on 03-01-2007
Since I recently migrated all of my blogs to SubText, I wanted to make sure that anyone visiting the old links on my WordPress blog were automatically redirected to the new location of all the past articles. I have been blogging “on record” since April of 2000. By “on record” I mean that I still have the posts going back that far within this blog. That’s almost seven years! Obviously there is a lot of content and things are linked from all over the Internet. Trying to minimize the move damage here is what I did to redirect the old blog URLs to the new location in SubText.
If you are migrating from WordPress to SubText, add the code below to the top of your index.php file and of course change the URL to match your own. It should be fairly simple to understand. The code takes the incoming REDIRECT_URL server variable and checks to see if it ends in a slash or is just a slash. Depending on state, a URL string is built up which points to the new location of the article within the SubText blog.
In order for this to work flawlessly, when you import your WordPress articles into SubText, be sure you save the data in the database column called “post_name”. This is the column that takes the titles and replaces spaces with dashes and so on. Otherwise you’ll never get a match via the title. As a result of adding this to WordPress anyone visiting an old link will be redirected.
Example
http://blog.zorka.com/2001/03/18/priceless-for-everything-else-there-is-mastercard
will now redirect the user to:
http://keithelder.net/blog/archive/2001/03/18/priceless-for-everything-else-there-is-mastercard.aspx
As a side benefit that I didn’t think about when I originally wrote this is it allows links that view postings by date to be redirected as well.
Example
will be redirected to:
Hooray! Finally I can comment on your blog without a login. The world is right again.