如何使用 mod_rewrite 隐藏实际目录?

发布于 2024-09-19 02:32:45 字数 745 浏览 3 评论 0原文

我正在托管同一 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉薄对峙 2024-09-26 02:32:45

您可以在发送到服务器时检查原始请求,该请求以 %{THE_REQUEST} 形式提供。检查 /_files/ 前缀表明请求属于后一种类型,然后您可以重定向到适当的格式:

RewriteCond %{THE_REQUEST} ^[A-Z]+\s/_files/
RewriteRule ^_files/[^/]+/(.*)$ http://%{HTTP_HOST}/f/$1 [R=301,L]

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:

RewriteCond %{THE_REQUEST} ^[A-Z]+\s/_files/
RewriteRule ^_files/[^/]+/(.*)$ http://%{HTTP_HOST}/f/$1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文