The QSA
flag means to append an existing query string after the URI has been rewritten. Example:
URL=http://example.com/foo/bar?q=blah
Rule:
RewriteRule ^foo/(.*)$ /index.php?b=$1
Result=/index.php?b=bar
Notice how the q=blah
is gone. Because the existing query string is dropped in favor of the one in the rule's target, (b=$1). Now if you include a QSA
flag:
RewriteRule ^foo/(.*)$ /index.php?b=$1 [QSA]
The result becomes=/index.php?b=bar&q=blah
The L
flag simply means to stop applying any rules that follow. Given the same URL, http://example.com/foo/bar?q=blah
, and given the rules:
RewriteRule ^foo -
RewriteCond %{REQUEST_URI} !^/bar.php
RewriteRule ^(.*)$ /bar.php?z=$1
The first rule gets applied and the URI gets passed through unchanged (via the -
target). The rewrite engine then processes the next rule, and the URI gets rewritten to /bar.php?z=foo/bar
. What happens when you add an L
to the end:
RewriteRule ^foo - [L]
RewriteCond %{REQUEST_URI} !^/bar.php
RewriteRule ^(.*)$ /bar.php?z=$1
The URL http://example.com/foo/bar
gets passed through untouched from the first rule, then stops because of the L
flag. If the URL is http://example.com/something/else
then the first rule doesn't match and the second rule gets applied, rewriting the URI to: /bar.php?z=something/else
Note that since the rewrite engine loops through all the rules until the URI stops changing, the L
flag will not prevent the looping, only any further rules from getting applied in the current iteration.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…