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
我正在请求以下 URL(请注意,我使用的是 ServerAlias
,而不是 ServerName
:
http://host2.example.com/test.php
我想让 test.php
以某种方式输出 ServerName
变量(host1.example.com
)。 ?
I have an Apache virtual host that looks like this:
<VirtualHost *:80>
ServerName host1.example.com
ServerAlias host2.example.com
DocumentRoot /srv/web/host1.example.com/pub
</VirtualHost>
I have the following file:
/srv/web/host1.example.com/pub/test.php
I am requesting the following URL (notice that I am using the ServerAlias
, not the ServerName
:
http://host2.example.com/test.php
I'd like to have test.php
output the ServerName
variable somehow (host1.example.com
). Is there any way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,当您通过别名访问 VirtualHost 时,没有原始的痕迹
任何
$_SERVER
变量中的SERVER_NAME
。我想到的唯一想法是设置一个环境变量:
这应该将
$_SERVER["MY_HOST"]
的值设置为正确的主机名。但不能保证,我从未在实践中尝试过这一点。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:
this should set the value of
$_SERVER["MY_HOST"]
to the correct host name. No guarantees though, I have never tried this in practice.对于我们的虚拟主机,默认的管理员电子邮件是
webmaster@
。多亏了这个,我可以通过With our webhost, the default admin email is
webmaster@<virtual-hostname>
. Thanks to this, I can get the virtuel host name through