使用更改的 RewriteCond 检查文件是否存在于多个位置
我想使用 mod-rewrite 在两个不同的位置检查文件:请求的 URL 以及“public”目录中请求的 URL。
这是我到目前为止所得到的:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/public/$0 !-f #this line isn't working RewriteRule ^(.*)$ index.php?$1 [L]
它可以正确确定文件是否在那里,但不能正确确定文件是否位于 /public/supplied/file/path/file.extension 。我该如何测试呢?
I want to use mod-rewrite to check for a file in two separate locations: at the requested URL, and at the requested URL within the "public" directory.
Here's what I have so far:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/public/$0 !-f #this line isn't working RewriteRule ^(.*)$ index.php?$1 [L]
It can correctly determine if the file is there, but it's not correctly determining if the file is at /public/supplied/file/path/file.extension. How do I test for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以做一个子请求。
-F
标志会将相对路径视为相对于 .htaccess 所在目录的路径。因此:请注意,
-F
意味着比- 更大的性能损失f
,因为生成的不仅仅是一个统计数据,而是一个子请求。您还应该添加B
标志来转义反向引用。You can do it a subrequest. The
-F
flag will treat relative paths as relative to the directory the .htaccess is in. So:Note that the
-F
implies a bigger performance penalty than-f
, since instead of just a stat, a subrequest is generated. You should also add theB
flag to escape your back reference.