如何使用mod_rewrite来检查多个文件夹的静态文件 [英] How to use mod_Rewrite to check multiple folders for a static file
问题描述
什么是用于检查一个给定文件的多个文件夹位置mod_rewrite规则。举例来说,如果我有一个文件夹结构:
What are the mod_Rewrite rules for checking multiple folder locations for a given file. For instance, if I have a folder structure of:
public/
css/
library1/
css/
library2/
css/
和我想请求 /css/somefile.css
来先检查公共/ CSS /
目录,然后级联公共/ LIBRARY1 / CSS /
然后公共/ library2 / CSS /
,返回404,如果一项资产不能在任何目录中找到。
and I want requests to /css/somefile.css
to first check the public/css/
directory, then cascade to public/library1/css/
then public/library2/css/
, returning a 404 if an asset cannot be found in any of the directories.
我的线沿线的思考
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond library1%{REQUEST_URI} -f
RewriteRule ^(.*)$ library1$1 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond library2%{REQUEST_URI} -f
RewriteRule ^(.*)$ library2$1 [L]
但是,这似乎并没有工作 - 我不知道如何检查文件的存在一个动态生成的路径上。
But this doesn't seem to work - I'm not sure how to check for file existence on a dynamically generated path.
推荐答案
请尝试以下规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/library1%{REQUEST_URI} -f
RewriteRule ^css/.+ library1%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/library2%{REQUEST_URI} -f
RewriteRule ^css/.+ library2%{REQUEST_URI} [L]
这篇关于如何使用mod_rewrite来检查多个文件夹的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!