Blog

Smart redirects

After migrating my blog over to WordPress, files have moved around a bit. Sites that linked to files on my site (including Google Images, as a prominent example) now link into the void, which is a bit of a pain. As a partial solution, I’ve added some .htaccess rules to help route visitors to the right place:

Redirect 301 /feeds/index.rss2 http://atastypixel.com/blog/feed
Redirect 301 /feeds/atom.xml http://atastypixel.com/blog/feed

However, that doesn’t solve all problems – after I reorganised my uploads, files are located at a very different path to their original home. So, I added a short script which does a search for requested files if they can’t be found, then redirects visitors to the right file.

Here is the script, and an accompanying .htaccess file needed to hook into it:

redirection.zip

To use it, put the script and the htaccess file into a folder on your site where you want it to take effect (for me, it went into ‘wp-content/uploads’). Then, modify the htaccess file – just set the RewriteBase field to the directory you’re in – and rename it to ‘.htaccess’.

, , . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. Posted September 10, 2008 at 5:57 pm | Permalink

    I know the pain of having to do 301 redirects for a new blogging platform. I wish there was a universal way to do it besides adding a different line for each web page in the htaccess file. It can take a “long” time if you have a ton of posts.