mod_rewrite:此RewriteRule的作用是什么? [英] mod_rewrite: what does this RewriteRule do?
问题描述
考虑到这些条件(我知道它们的意思/作用):
Given these conditions (I know what they mean/do):
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
第一规则有什么作用?那个孤独的破折号是做什么用的?
What does the first rule do? What is that lonely dash for?
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
我已经将它与Zend Framework结合使用了一段时间了,但是我从来没有真正了解到第一个规则的确切作用.
I've been using this for quite some time now in combination with the Zend Framework, but I never really got what the first rule does exactly.
推荐答案
RewriteCond
指令仅描述了 RewriteRule
指令.因此,RewriteCond
必须始终与RewriteRule
关联.
The RewriteCond
directive just describes an additional condition for a RewriteRule
directive. So RewriteCond
must always be associated with a RewriteRule
.
在您的情况下,三个RewriteCond
可能属于第一个RewriteRule
,如下所示:
In your case the three RewriteCond
probably belong to the first RewriteRule
like this:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
如果RewriteRule
的模式与当前请求URL(之前剥离的每个目录路径)和匹配,则应用此规则.
Now this rule is applied if the pattern of the RewriteRule
matches the current request URL (per-directory path stripped before) and if the condition is fulfilled.
在这种情况下,仅当将请求URL映射到文件系统时,该条件与文件大小大于0的现有文件(-s
)或符号链接(-l
)或目录(-d
).因此,您的规则将应用于可以映射到文件系统中现有内容的任何URL(^.*$
匹配任何内容).替换-
仅表示不更改任何内容. NC (无大小写,不区分大小写,在这种情况下无用)和 L (如果适用,则是最后一条规则)为
In this case the condition is only true if when mapping the request URL to the filesystem it matches either an existing file with the file size greater than 0 (-s
), or a symbolic link (-l
) or a directory (-d
). So your rule will be applied for any URL (^.*$
matches anything) that can be mapped to something existing in your filesystem. The substitution -
just means to not change anything. And the NC (no case, case insensitive, useless in this context) and L (last rule if applied) are flags that modify either the pattern, replacement or the execution of the rule.
这篇关于mod_rewrite:此RewriteRule的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!