【发布时间】:2019-10-02 19:50:40
【问题描述】:
我已经做了很多谷歌搜索,尝试了不同的东西,但我仍然没有弄清楚为什么我的 $_SERVER['DOCUMENT_ROOT'] 会改变。我认为这与这条线有关
RewriteRule ^(.*)$ D:/data/v5.3/%1/%2/$1 [L]
访问http://test.example.com时的输出
<?php echo $_SERVER['DOCUMENT_ROOT']; ?> is "D:\data\v5.3\test\www"
访问http://test.redesign.example.com和http://test.code.example.com时的输出
<?php echo $_SERVER['DOCUMENT_ROOT']; ?> is "D:/data"
路径:
d:\data\v5.3\test\
文件夹结构:
- code
- redesign
- www
这是我的 httpd-vhosts.conf 中的内容:
<IfModule mod_vhost_alias.c>
<VirtualHost *:80>
ServerAlias *
UseCanonicalName Off
VirtualDocumentRoot "D:/data/v5.3/%1/www"
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*?)\.(code|redesign|new|old)\.(.*)$ [NC]
RewriteRule ^(.*)$ D:/data/v5.3/%1/%2/$1 [L]
<Directory "D:/data/v5.3">
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
访问http://test.example.com时的输出
<?php echo $_SERVER['DOCUMENT_ROOT']; ?> should be "D:\data\v5.3\test\www" (this is fine)
访问http://test.redesign.example.com时或 http://test.code.example.com的输出
<?php echo $_SERVER['DOCUMENT_ROOT']; ?> should be "D:\data\v5.3\test\redesign" or
"D:\data\v5.3\test\code" (depending on what's in URL after test.)
注意:
dirname(__FILE__) is working just fine, so it's only an issue
with $_SERVER['DOCUMENT_ROOT'] which some of my websites might rely on
【问题讨论】:
-
输入是指输出,不是吗?
-
糟糕!我的错,我要编辑我的问题。你是对的,我的意思是输出不是输入。
标签: php apache mod-rewrite