Here’s a sort-of-interesting problem I’ve been working on recently, and which might help prevent an internet stranger or two from pulling their hair out. When you’re moving from one blog to another, how do you set things up so that folks stumbling across your old site are sent to the new one? This came up while Emily and I were working on Brian’s new site. His existing Typepad site had URLs like this:
I knew that I wanted to clean up the formatting of these a little bit — for one thing, the .html would have to go, as I intended to use some PHP in the pages (on a web server with a standard configuration, only files ending in .php or .php5 are processed for PHP). And that “/home/” seemed extraneous, too.
I did try to make the two similar, though, to simplify things. By default Movable Type creates its URLs from the entry’s title, transforming it into a unique identifier called the basename. I altered MT’s default basename length so that it was 15 characters, matching the length of Typepad’s basenames. I set up the new mapping in MT’s Settings/Publishing area, and ended up with new URLs that looked like this:
The index.php on the end can be left off — if you ask a Linux web server for a directory, it’ll look for “index.php” or “index.html” or “index.htm” and send it back if it finds it. This lets you have slightly tidier-looking URLs. So our new URL is actually:
location.href = location.href.replace(/beutler\.typepad\.com/,'www.brianbeutler.com').replace(/\/home\//,'/').replace(/\.html$/,'/').replace(/\-/g,'_');
This looks complicated, but it really just does a few things to the URL (whatever the URL may be):
- Replace “beutler.typepad.com” with “www.brianbeutler.com”
- Replace “/home/” with “/”
- Replace the “.html” at the end of the URL with “/”
- Change all hyphens in the URL to underscores
It then sends the browser to the new URL.
Done! All I had to do now is deliver the website, lean back and adopt an attitude of extreme self-satisfaction.
Except… no. I wasn’t done. Everything was actually much, much worse than I thought.