I often have to change the location of web pages, and try to make sure nothing breaks in the process. Ideally, you won’t see any changes at all, and clients won’t lose any functionality whatsoever.
This got me to thinking about my archives. Not too long ago, I explained how I had updated the old archive pages to include the link to the new pages. This was actually working pretty well, but I was now also getting another entire copy of each page in this old archive section.
If I didn’t need to update those old pages, that’s one thing – as they could be static. But as comments and trackbacks and changes and stuff flow to those pages, they need updating, at which point all of them are rebuilt. Geez.
So after thinking on it for days – a process which probably would have taken most people about three minutes – I finally had an epiphany. The answer was simple: PHP. I already had PHP in place in several places on the site. It was relatively easy to implement in the first place, plus it’s already in place now. So it’s remarkably easy to make use of PHP to automatically redirect those pages to where I want them:
<?php
header(“Location: http://www.cxliv.org/newurl”);
?>
And that’s it. Now, when someone tries the old URL, they are redirected automatically to the new URL. Best of all, there’s only a single copy of the page – at the new URL. The only thing in the old URL is that one line of redirecting PHP. File sizes went from several thousand bytes per old archive to around one hundred bytes, for a significant space savings.