Subdomain to subdirectory
If you ever need to pass a non-existent subdomain as an argument to another script, you’ll need this:
RewriteCond %{HTTP_HOST} !^www\.izeit\.nu$ RewriteCond %{HTTP_HOST} ^([^\.]+)\.izeit\.nu$ RewriteRule (.*) /home/hjennerway/izeit.nu/hosted/current/index.php?cal=%1
I used it for my LiveZeit project, which is a hosted version of iZeit. It takes a subdomain, then passes it to index.php as a GET variable. So if you go to blah.izeit.nu, you're really seeing izeit.nu/hosted/current/index.php?cal=blah. First you need to set up Wildcard DNS with your host so that every subdomain resolves to the same IP as the www subdomain, then add the lines above to a .htaccess file. The first line tells Apache to ignore the www domain, the second tells it to only look for subdomains without dots in them, then the third transparently redirects the subdomain to a script on your server. Then you can use PHP to take the query string from $_SERVER['REQUEST_URI'], explode it, and use it to set GET variables.
$qstring = explode("&",substr($_SERVER['REQUEST_URI'],strpos("?",$_SERVER['REQUEST_URI'])+1)); foreach($qstring as $gvar) { list($k,$v) = explode("=",$gvar); $_GET[$k] = $v; }







Comments
Leave a Comment