404 Cheat
Sep 1, 2004 · 2 minute readWhen our CEO came to me and told me that I had two weeks to design and implement a new website, I knew I was in trouble. In the years since our site first went live, it had grown a lot of ‘cruft’, information that was now completely useless. I started by going to our head of marketing and discussing what didn’t need to be transitioned across to the new website.
Although the CEO was happy with the look of the new site and liked the way we’d trimmed it down, he still insisted that all content be available. So I cheated a little.
I moved the old website to another directory (called ‘oldsite’), and set up a new virtualhost for ‘oldsite.ourdomain.com’. I gave this its own 404 page saying “Your page could not be found”. In the new site, I also gave it a custom 404 page - actually, a PHP script, which would redirect to oldsite.ourdomain.com
So, someone requesting a document we hadn’t transitioned to the new site:
-
browser requests http://www.ourdomain.com/somepage.html
-
Server 404’s, goes to custom 404.php page
-
404.php redirects the request to http://oldsite.ourdomain.com/somepage.html
It’s a simple procedure, but one which saved my neck. In the hopes of saving someone else’s neck, here’s that simple 404.php page
<?php
$uri=getenv("REQUEST_URI");
header("Location: http://oldsite.ourdomain.com$uri");
echo $uri;
?>