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.”
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:
- If the URL or link your visitor is using doesn’t exist, the webhost will redirect it to the custom 404 page.
- If the URL does contain shtml, translate the old URL into a new one, replacing shtml with php.
- Redirect the visitor to the brand new URL.
You may also download Dominade here. And thanks to Todd for the inspiration.