Apache / PHP:无论如何通过PHP检索ServerName设置

我有一个Apache虚拟主机,如下所示:
<VirtualHost *:80>
    ServerName host1.example.com
    ServerAlias host2.example.com
    DocumentRoot /srv/web/host1.example.com/pub
</VirtualHost>
我有以下文件:
/srv/web/host1.example.com/pub/test.php
我要求提供以下网址(注意我使用的是
ServerAlias
,而不是
ServerName
http://host2.example.com/test.php
我想
test.php
以某种方式输出
ServerName
变量(
host1.example.com
)。有没有办法做到这一点?     
已邀请:
显然,当您通过别名访问VirtualHost时,没有原始的痕迹
SERVER_NAME
在任何
$_SERVER
变量中。 想到的唯一想法是设置一个环境变量:
SetEnv MY_HOST host1.example.com
这应该将
$_SERVER["MY_HOST"]
的值设置为正确的主机名。虽然没有保证,但我从未尝试过这种做法。     

要回复问题请先登录注册