从服务器根目录到Apache根目录重定向 [英] Redirect from server root directory to apache root directory

查看:1399
本文介绍了从服务器根目录到Apache根目录重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Ubuntu 14.04与LAMP简单的HTTP服务器,并把我的HTML,PHP和js文件到Apache根目录下的 /无功/网络/ 。这些文件中的所有路径是绝对的,看起来像 /script1.php /subdir/script.php 。 Web服务器的目录树如下:

I have made simple http server on Ubuntu 14.04 with LAMP and put my html, php and js files to apache root directory /var/www/. All paths within these files are absolute and looks like /script1.php or /subdir/script.php. Directory tree of web server looks like:

/
|---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

这个问题在所有路径从根服务器开始目录的地步。

The problem is in the point that all paths begin from root server directory.

例如,PHP命令执行opendir('/')显示列表:

for example, php command opendir('/') shows list:

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

但我需要列表一样,

but I need list like that

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

所以,我怎样才能让Apache认为/表示不根Web服务器目录中,但根apache目录?

So, how can I make Apache think that '/' means not root web server directory, but root apache directory?

推荐答案

执行opendir需要一个实际的路径不是Web服务器的文档根目录的路径。因此,执行opendir(/)正常工作,向您展示了服务器的根目录。

opendir takes an actual path not the path of the web server's document root. Thus, opendir("/") is working correctly to show you the server's root directory.

正如普京所说,而用

opendir($_SERVER["DOCUMENT_ROOT"]);

或可能是更好的安全性。

or probably better for security

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

这篇关于从服务器根目录到Apache根目录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆