<?php
$this_URL = $HTTP_REFERER;
$pass1 = str_replace("http://", "", $this_URL);
$pass2 = explode(".", $pass1);
$subdomain = $pass2[0];
if (($subdomain != "www") && $subdomain != "")){
include($subdomain.".php"); // this will work as a header redirect as well but an include hides the fact it is not a real subdomain set in apache
}
?>
Just add each subdomain to your hosts file tested in windowsand linux environments running php 5 and apache 2