I have an Apache virtual host that looks like this:
ServerName host1.example.com
ServerAlias host2.example.com
DocumentRoot /srv/web/host1.example.com/pub
/srv/web/host1.example.com/pub/test.phpI am requesting the following URL (notice that I am using the ServerAlias, not the ServerName:
http://host2.example.com/test.phpI’d like to have test.php output the ServerName variable somehow (host1.example.com). Is there any way to do that?
……………………………………..
Apparently, when you access a VirtualHost through the alias, there is no trace of the original SERVER_NAME in any of the $_SERVER variables.
The only idea that comes to mind is setting an environment variable:
SetEnv MY_HOST host1.example.comthis should set the value of $_SERVER["MY_HOST"] to the correct host name. No guarantees though, I have never tried this in practice.