As I mentioned in a previous post, I moved my blog from my own host, to Google’s blogger. As a result, there are ~ 100 old blog posts that are linked to from all over the place and I’d like to have a graceful way to re-direct. The previous post mentioned updated the header with a 301 redirect. Going through so many old posts, and updating each one was nuts, so I wrote a small ruby script to handle the duties.
# This script will traverse the directory given as the first argument
# and replace the contents of all files with the 'redirect_text'
# some special conditions: it assumes that they are php redirects, but you
# can use <meta> redirect tags as well for plain HTML
dir = ARGV
header("HTTP/1.1 301 Moved Permanently");
# find all the files that were published by blogger (they are all in their
# respective year directories)
Find.find(dir) do |path|
f=File.open(path,'w') # open 'w' truncates the file