PHP redirect script

February 16th, 2007

When developing and/or designing websites for clients, I often use a quasi versioning system to keep track of older copies of their respective projects. For example, if I often create a repository for all of my development such as http://mybusiness.com/clientname and all subsequent revisions of the project in directories reflecting their version number (http://mybusiness.com/clientname/1/ and http://mybusiness.com/clientname/3/ and so on).

The beauty of this is that when a client inevitably changes their mind regarding an alteration to a design/feature, all of my original work is not lost, and I can easily refer them back to previous revision for comparison.

Below is a simple PHP snippet I use to redirect the user to the latest version of the project. This saves them having to know what number the revisions is up to, and can merely navigate to http://mybusiness.com/clientname and be taken to the most recent trunk.

<?php
$host  = $_SERVER['HTTP_HOST'];
$uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\');
$revision = '1/';
header("Location: http://$host$uri/$revision");
exit;
?>

Save this as index.php in your top level directory, and simply change the variable $revision to reflect the current version.

This entry was posted on Friday, February 16th, 2007 at 1:25 pm and is filed under PHP, Web Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to 'PHP redirect script'

  1. Gravatar 1 jostmart Says:

    I am doing almost the same thing, but with Apache. I simply change the sites document root to the revision I want to use. Or make a symlink say “current” which you point Apache to. Then make the symlink point to the revision you want to use.

Leave a Reply

XHTML: Permitted tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>