Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Dynamic Subdomains and PHP's DOCUMENT ROOT


mattdeclaire - 8:46 pm on May 2, 2008 (gmt 0)


We are starting to set up an internal development environment on our office. We are using the TLD dev locally. We've got DNS routing STDs to individual computers in the office.

So I've got *.matt.dev pointed at my local machine.
My web root is at
/Users/mdeclair/Sites/

I would like to have subdomains pointed at directories in my web dir.

test.matt.dev would point to /Users/mdeclair/Sites/test/

I've seen many ways to do this, and have "successfully" done it in the two ways shown below.

First:

RewriteEngine on
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^(.+)\.matt\.dev(.*) /Users/mdeclair/Sites/$1$2

Second:

NameVirtualHost *
<VirtualHost *>
ServerName matt.dev
ServerAlias *.matt.dev
VirtualDocumentRoot /Users/mdeclair/Sites/%-3
UseCanonicalName Off
</VirtualHost>

The problem I've run into is that when testing my PHP scripts, the variable $_SERVER['DOCUMENT_ROOT'] comes up as /Users/mdeclaire/Sites/ without the appropriate subdomain included.

So that is my hurdle.

Bonus question!
I'd love to have the subdomaining system recursive, such that
hey.dude.matt.dev =>
/Users/mdeclair/Sites/dude/hey/,
and furthermore
man.bear.pig.matt.dev =>
/Users/mdeclair/Sites/pig/bear/man/,
and so on.


Thread source:: http://www.webmasterworld.com/apache/3640691.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com