Dominade

In an effort to garnish additional monies from my webhost, I suggested to our friend and fellow countryman Todd Dominey that he consider making the switch. He’d had some issues with his previous host, and was looking for a new provider.

Once the transfer was complete, a business of filling out a web form or two, FTP’ing files, and updating the registrar with new name-servers, things were looking good and Dominey was passing around cigars and filling our coffers with wine.

“I’m glad Dreamhost still supports server side includes,” he said. “I’ve got a ton of old .shtml pages.”

“You’re not still using .shtml files when you have PHP available, are you?” I asked.

“Well, I know that PHP is faster and better-behaved, and I’ve switched to .php for all of my new posts, but I’ve got years of old posts saved as .shtml files, and many people still have links to those URL’s. I can’t just break those links, and I can’t expect everyone to go back and change everything.”

“I’ve got just the thing,” I told him. “It will be similar to the JavaScript I ”http://www.hivelogic.com/158.html" title=“Johnny Carson Returns to Late Night”>wrote when I was changing my site around a bit, but we’re wasting time!"

With one sweep of my arm across the table, I knocked the mess of glassware to the floor and began composing. Using nothing more than a filthy paper table-napkin as my tablet and a cigarette-butt as a pencil, I began scrawling code.

“What you want to do,” I said as I wrote, “is take any incoming request which has shtml in it, and replace it with php. Then redirect to the newly formed URL. A simple matter, really. And we’ll use your custom-404 page as the means of redirection.”

“I get it,” he said. “Sounds perfect – but if we use the 404 page, what will happen if there’s a genuine 404 error? Will it redirect that as well?”

“Good question, but I’ve got that bit worked out already. You see, the script will only redirect URL’s with shtml in them,” I told him. It works like this:

  1. If the URL or link your visitor is using doesn’t exist, the webhost will redirect it to the custom 404 page.
  2. The 404 page will use a bit of JavaScript to check and see if the URL ends with shtml. If not, it’s just a bad URL, so it will display the standard “Page not found” warning.
  3. If the URL does contain shtml, translate the old URL into a new one, replacing shtml with php.
  4. Redirect the visitor to the brand new URL.

And with that, this simple bit of JavaScript, known henceforth as Dominade, was born. Here’s the code:

You may also download Dominade here. And thanks to Todd for the inspiration.

More articles in the Archive →