【问题标题】:Redirect from server root directory to apache root directory从服务器根目录重定向到 apache 根目录
【发布时间】:2015-09-02 07:28:27
【问题描述】:

我在 Ubuntu 14.04 上使用 LAMP 制作了简单的 http 服务器,并将我的 html、php 和 js 文件放入 apache 根目录 /var/www/。这些文件中的所有路径都是绝对路径,类似于 /script1.php/subdir/script.php。 Web 服务器的目录树如下所示:

/
|---var
    |---www
        |---script1.php
        |---subdir
|---usr
|---home
|---etc 

文件/etc/apache2/sites-available/000-default.conf

   ServerAdmin webmaster@localhost
   DocumentRoot /var/www

    <Directory />
            Options Indexes FollowSymLinks
            AllowOverride All
            Order Allow,Deny
            Allow from all
    </Directory>

    Alias /data /var/www/
    <Location /data>
            DAV On
            AuthType Digest
            AuthName "webdav"
            AuthUserFile /usr/local/apache2/.digest_passwd.dav
            Require valid-user
            Order Allow,Deny
            Allow from all
            DirectoryIndex disabled
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

问题在于所有路径都从根服务器目录开始。

例如php命令opendir('/')显示列表:

/
|---var
|---usr
|---home
|---etc 

但我需要这样的列表

/
|---subdir
|---script1.php

那么,我怎样才能让 Apache 认为 '/' 不是根 Web 服务器目录,而是根 apache 目录?

【问题讨论】:

标签: php apache .htaccess directory root


【解决方案1】:

opendir 采用实际路径,而不是 Web 服务器文档根目录的路径。因此,opendir("/") 可以正常工作,向您显示服务器的根目录。

正如弗拉基米尔所说,宁可使用

opendir($_SERVER["DOCUMENT_ROOT"]);

或者可能更好的安全性

opendir(filter_var($_SERVER["DOCUMENT_ROOT"], FILTER_INPUT_STRING));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-21
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多