Apache 使用“重写引擎”从被拒绝的目录中直接删除 设置
根/Apache 使用“重写引擎”从被拒绝的目录中直接删除 设置,apache,mod-rewrite,permissions,Apache,Mod Rewrite,Permissions,根/ .htaccess: Deny from All RewriteEngine On RewriteRule secret.txt /root/public/welcome.txt Allow from All secret.txt 公开的/ .htaccess: Deny from All RewriteEngine On RewriteRule secret.txt /root/public/welcome.txt Allow from All 欢迎使用.txt 问
- .htaccess:
Deny from All RewriteEngine On RewriteRule secret.txt /root/public/welcome.txt
Allow from All
- secret.txt
- 公开的/
- .htaccess:
Deny from All RewriteEngine On RewriteRule secret.txt /root/public/welcome.txt
Allow from All
- 欢迎使用.txt
- .htaccess:
/root/secret.txt
的请求将导致403(禁止)响应,该响应告诉我无法访问/root/secret.txt
。(允许直接请求/root/public/welcome.txt
)
因此,在我看来,RewriteEngine
对将被Deny from All
指令拒绝的请求没有任何作用
问题
如果有人知道如何获得预期的/root/public/welcome.txt
服务,那就太好了。不过,如果有人能帮我实现最终目标,那就更好了
目标
我决定写下我的最终目标,因为也许我只是看错了方向
我想从根目录中的所有中拒绝,并让子目录决定何时使用
Allow
覆盖它。然后,我还希望Apache将导致403或404的所有请求重写为单个特定文件。到目前为止,我正计划用来实现这一点-U
标志,但我无法克服最初的问题。您可以在根目录下的.htaccess文件中尝试此操作:
Deny from All
ErrorDocument 404 /Error403_404.php
ErrorDocument 403 /Error403_404.php
“Error403_404.php”就是一个例子。替换为403和404错误处理程序脚本。您好,谢谢您的回答。不过,恐怕你误解了我问题的一部分。在我的示例中,public/welcome.php是我希望404和403重定向到的特定文件。但是,您的回答确实让我了解了ErrorDocument指令。我会玩一玩的。我会让你知道的。:)你的问题中没有提到错误文件。但是如果这是唯一的问题,只需将
Error403_404.php
替换为welcome.php
。如果删除Deny
指令和ErrorDocument
指令之间的所有行,请告诉我是否还有其他内容。答案完全足够了。我确实看错了方向,我甚至不需要重写引擎
!:)更新。很高兴你找到了做这件事的方法。