I have two virtual hosts declared: localhost and test.
Both use the SetEnv
directive and point to the same DocumentRoot:
NameVirtualHost *:80
<VirtualHost _default_:80>
DocumentRoot "/Users/mf/Sites/test"
SetEnv FROM_ROOT 'i like tacos' ## <- SetEnv
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Users/mf/Sites/test"
<Directory "/Users/mf/Sites/test">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SetEnv FROM_VHOST 'set in localhost vhost' ## <- SetEnv
</VirtualHost>
<VirtualHost *:80>
ServerName test
DocumentRoot "/Users/mf/Sites/test"
<Directory "/Users/mf/Sites/test">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SetEnv FROM_VHOST 'set in test vhost' ## <- SetEnv
</VirtualHost>
I have a test file /Users/mf/Sites/test/dump.php:
var_dump( $_SERVER );
For http://test/
everything works as I'd expect, $_SERVER['FROM_VHOST']
is available. dump.php outputs:
array (size=33)
'UNIQUE_ID' => string 'UY7bHMCoAXIAABkbAkMAAAAC' (length=24)
'FROM_VHOST' => string 'set in test vhost' (length=17)
'HTTP_HOST' => string 'test' (length=4)
…
For http://localhost/
things break down:
array (size=34)
'UNIQUE_ID' => string 'UY7bA8CoAXIAABkZAhQAAAAA' (length=24)
'FROM_ROOT' => string 'i like tacos' (length=5)
'HTTP_HOST' => string 'localhost' (length=9)
…
?
- Why does localhost not have a
FROM_VHOST
environment variable? - Why does only localhost see the
FROM_ROOT
environment variable?