.htaccess - 在 DocumentRoot 后面的 Mod-Rewrite 加载文件

标签 .htaccess mod-rewrite

我正在使用 .htaccessmod_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/

相关文章:

php - .htaccess - 子域的 DocumentRoot

php - 为什么 DirectoryIndex index.php index.html 不工作?

regex - htaccess 301 重定向 - 删除查询字符串 (QSA)

javascript - CORS - 不存在 'Access-Control-Allow-Origin' header

css - htaccess 需要本地中断背景图像

apache - 重写条件以从智能手机检查移动用户代理

wordpress - 让 WordPress 永久链接在 MAMP 安装上运行

.htaccess - 使用.htaccess时如何使mod_rewrite *不*执行主目录扩展

apache - Mod Rewrite,将参数从 URL1 传递到 URL2

.htaccess - 在 htaccess 中传递的持久查询字符串 (mod_rewrite)