如何使用 mod_rewrite 隐藏实际目录?
我正在托管同一 WordPress 安装的几个域,现在我想要一个每个域的文件夹,用于存放我需要放在那里的一些不同文件。
本质上我想像这样映射:
URL Path webbfarbror.se/f/* _files/webbfarbror.se/* grapefrukt.com/f/* _files/grapefrukt.com/*
这个小片段很好地完成了这项工作,RewriteCond 让我在每个域的基础上启用和禁用它。
ReWriteCond %{HTTP_HOST} webbfarbror.se
ReWriteRule ^f/(.*)$ _files/%{HTTP_HOST}/$1 [L]
但是,一个文件 http://grapefrukt.com/f/awesome.jpg也可以通过其“真实”URL http://grapefrukt.com/_files/grapefrukt 进行访问.com/awesome.jpg
我所有的尝试都会导致无限的来回重定向。
如何禁用通过后一个 URL 的访问?
I am hosting a couple of domains of the same wordpress installation, now I'd like to have a per-domain folder for some various files I need to put up there.
Essentially I want to map like this:
URL Path webbfarbror.se/f/* _files/webbfarbror.se/* grapefrukt.com/f/* _files/grapefrukt.com/*
This little snippet does the job nicely and the RewriteCond let's me enable and disable this on a per domain basis.
ReWriteCond %{HTTP_HOST} webbfarbror.se
ReWriteRule ^f/(.*)$ _files/%{HTTP_HOST}/$1 [L]
However, a file at say, http://grapefrukt.com/f/awesome.jpg is also accessible at it's "real" URL http://grapefrukt.com/_files/grapefrukt.com/awesome.jpg
All my attempts result in infinite redirects back and forth.
How do I disable access through the latter URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在发送到服务器时检查原始请求,该请求以
%{THE_REQUEST}
形式提供。检查/_files/
前缀表明请求属于后一种类型,然后您可以重定向到适当的格式:You can examine the original request as it was sent to the server, which is available as
%{THE_REQUEST}
. Checking for the/_files/
prefix indicates that the request was of the latter type, and you can then redirect to the appropriate format: