简体   繁体   中英

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

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM