【发布时间】: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 目录?
【问题讨论】:
-
我不认为这是可能的,最好使用变量来存储 document_root 绝对路径,然后与实际项目文件夹连接 // $site_root='/vat/www/'; opendir($site_root.'subdir');或看这里php.net/manual/en/language.constants.predefined.php
-
或使用 $_SERVER['DOCUMENT_ROOT']; php.net/manual/en/reserved.variables.server.php
-
感谢您的回答。我试试看
-
改变Apache的根目录怎么样?
标签: php apache .htaccess directory root