When learning the Rewrite function of Apache. I don’t know what the L in flags does
For example, the following code:
RewriteRule ^(.*) first.php?key= [L]
RewriteRule ^(.*) second.php?key=
Since you don’t want to execute the following code, wouldn’t you just comment and delete it directly? Why do you have to use L
習慣沉默2017-05-16 13:01:47
Judging from your configuration file, the latter sentence is indeed unnecessary. But this is only limited to the configuration example you gave. It doesn’t mean that L
没用,L
still has its own application scenarios
Hypothesis
RewriteRule /([0-9]+).html /test1.php?id=
RewriteRule /(.*) /test2.php?id=
In this configuration, my request is 123.html, then when the request reaches apache, apache will start matching rules from top to bottom:
The first step, match RewriteRule /([0-9]+). html /test1.php?id=$1
, found that the match passed, because there is no mark to stop, so continue to execute the code RewriteRule /([0-9]+).html /test1.php?id=
, 发现匹配通过, 因为没有标记停止,所以继续向下执行代码
第二步,匹配RewriteRule /(.*) /test2.php?id=
, 发现匹配通过,因为是最后一条规则,且是通过的规则,则最终请求被导向test2.php?id=123.html
The second step, match RewriteRule /(.*) /test2.php?id =$1
, it is found that the match is passed, because it is the last rule and it is a passed rule, then the final request is directed to the page of test2.php?id=123.html
But if so:
RewriteRule /([0-9]+).html /test1.php?id= [L]
RewriteRule /(.*) /test2.php?id=
After the first match passed, a mark was foundL
,则apache停止向下继续匹配,而是直接就导向了test1.php?id=123
的页面; 而其他的请求(比如:abc.html)只有当第一条规则不通过的时候,才会继续匹配第二条规则, 请求被导向至test2.php?id=abc.html