Apache/PHP:通过 PHP 检索 ServerName 设置的任何方式 [英] Apache/PHP: Any way to retrieve the ServerName setting via PHP

查看:35
本文介绍了Apache/PHP:通过 PHP 检索 ServerName 设置的任何方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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,而不是 ServerName:

I am requesting the following URL (notice that I am using the ServerAlias, not the ServerName:

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

我想让 test.php 以某种方式输出 ServerName 变量(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?

推荐答案

显然,当你通过别名访问一个 VirtualHost 时,没有任何原来的痕迹任何 $_SERVER 变量中的 SERVER_NAME.

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.

这篇关于Apache/PHP:通过 PHP 检索 ServerName 设置的任何方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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