问题
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