使用 mod_rewrite 显示另一个目录中的文件
我已将应可从外部访问的项目中的所有文件移至单个 public
目录 - 这样我就可以将可访问的目录列入白名单,而不是将必须保持隐藏的目录列入黑名单。
但是,我无法强制 apache 重写此类网址:
- www.example.com/images/flower.jpg
来获取
/public/images/flower .jpg
我想出的唯一合理的解决方案是以下几行:
RewriteCond public\/%{REQUEST_FILENAME} -f #if a file exists in the public dir,...
RewriteRule .* public/$0 [L] #display it
不出所料,它不起作用,更准确地说,RewriteCond
部分,我无法让它匹配。
我完全不知所措,有人可以帮忙吗?
作为一个附带问题,如何调试 .htaccess
配置?如果我不知道问题是什么以及在哪里,我就无法解决问题。
I have moved all files from a project that should be accessible from outside to a single public
directory - so that instead of blacklisting directories that must remain hidden, I could whitelist accessible ones.
However I cannot force apache to rewrite this kind of urls:
- www.example.com/images/flower.jpg
to fetch
<DOCUMENT ROOT>
/public/images/flower.jpg
Only rational solution I came up with was something among those lines:
RewriteCond public\/%{REQUEST_FILENAME} -f #if a file exists in the public dir,...
RewriteRule .* public/$0 [L] #display it
Unsurprisingly, it does not work, more precisely, the RewriteCond
part, I can't get it to match.
I am completely at loss, could someone help?
As a side question, how do you debug .htaccess
configurations? I can't fix the problem if I don't know what and where it is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用
-f
测试现有文件,则需要提供如下的绝对文件系统路径:否则使用
-F
通过子请求进行检查:If you want to test for an existing file with
-f
, you need to provide an absolute file system path like this:Otherwise use
-F
to do the check via a subrequest: