$_SERVER['DOCUMENT_ROOT'] returns path with repeated directory name

南笙酒味 提交于 2019-12-13 19:14:54

问题


I am seeing a strange behavior when accessing $_SERVER['DOCUMENT_ROOT'] on a subdomain. It contains a duplicate folder name which does not exist.

Here is the the relevant output of $_SERVER:

[DOCUMENT_ROOT] => /var/www/sub.domainname.com/sub.domainname.com
[SCRIPT_FILENAME] => /var/www/sub.domainname.com/index.php

It should be:

[DOCUMENT_ROOT] => /var/www/sub.domainname.com

Here is the virtual host configuration:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName sub.domainname.com

    DocumentRoot /var/www/sub.domainname.com
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/sub.domainname.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>    
</VirtualHost>

回答1:


This issue is likely caused by a mis-configured webserver, the PHP documentation says this $_SERVER['DOCUMENT_ROOT'] contains the script directory as defined in the servers config file. Which may therefore be different to the actual script directory location.

DOCUMENT_ROOT
The document root directory under which the current script is executing, as defined in the server's configuration file.

Source: PHP Reserved Variables $_SERVER[] Manual Page



来源:https://stackoverflow.com/questions/24123839/serverdocument-root-returns-path-with-repeated-directory-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!