我正在使用 .htaccess
和 mod_rewrite
指向驻留在 DocumentRoot 后面的文件。我的文件夹结构如下所示:
home/
webroot/
other_files/
我有一个
.htaccess
webroot 中的文件,内容如下:重写引擎开启
重写规则 ^(.*)$/home/other_files/$1
如果我尝试访问 http://example.com/file.html我收到以下错误:
The requested URL /home/other_files/file.html was not found on this server.
甚至可以加载 DocumentRoot 后面的文件吗?如果是这样,有人可以指出我正确的方向吗?
最佳答案
我相信你需要添加一个部分
<Directory "/home/other_files">
(options)
</Directory>
到您的服务器配置之前 apache 将能够从中提供任何服务。例如,我的 DocumentRoot 是/var/www 但默认可用站点中有此部分:
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
然后,您可以重写 URL 以转到/doc/,服务器将知道从何处获取文件。
关于.htaccess - 在 DocumentRoot 后面的 Mod-Rewrite 加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8441/