阿帕奇/ PHP:反正检索服务器名通过PHP设置 [英] Apache/PHP: Anyway to retrieve the ServerName setting via PHP

查看:164
本文介绍了阿帕奇/ PHP:反正检索服务器名通过PHP设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样一个Apache虚拟主机:

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>

我有以下文件:

/srv/web/host1.example.com/pub/test.php

我请求以下URL(请注意,我用的是 ServerAlias​​ ,而不是服务器名称

http://host2.example.com/test.php

我想有 test.php的输出服务器名称变量以某种方式( host1.example.com )。有没有办法做到这一点?

I'd like to have test.php output the ServerName variable somehow (host1.example.com). Is there any way to do that?

推荐答案

显然,当你通过别名访问虚拟主机,没有原来的痕迹
SERVER_NAME 中的任何 $ _ SERVER 变量。

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.com

这应该设置 $ _ SERVER [MY_HOST] 到正确的主机名的值。虽然没有保证,我从来没有在实践中尝试过这一点。

this should set the value of $_SERVER["MY_HOST"] to the correct host name. No guarantees though, I have never tried this in practice.

这篇关于阿帕奇/ PHP:反正检索服务器名通过PHP设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆