apache url rewriting how does [L] really flag works?
I just spended few hours trying to understand hoes does the [L]
flag really works.
I read documentation, tutorial, but nothi开发者_StackOverflowng could explain my problem.
I have a simple .htaccess
file:
RewriteEngine On
RewriteRule ^ressources/(.+)$ App/ressources/$1
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [L]
RewriteRule ^(?!index.php)(.*)$ index.php?path=$1 [QSA]
It's just working fine, except when the user request a ressource file that not exists like : ressources/notexist.css
.
So if i go to:
http://localhost/htaccessdir/ressources/css/dot-luv/jquery-ui-1.8.16.custom.css
That works and it get the css code because the file exists.
But if i go to:
http://localhost/htaccessDir/ressources/css/dot-luv/notexists.css
the index page is loaded with path value:
App/ressources/css/dot-luv/notexists.css/css/dot-luv/notexists.css
instead of :
App/ressources/css/dot-luv/notexists.css
And this could be resolve by adding the [L]
flag for the first rule :
RewriteRule ^ressources/(.+)$ App/ressources/$1 [L]
I do not understand why it is not working without the [L]
flag.
Could anybody explain me that's behaviour ?
Thanks
If the L
flag is not set, the rest of the rules will also be checked and the last match will be applied. L
stands for Last and prevents further rules from being checked.
mod_rewrite
keeps applying rules in the order they are defined. A rule will only be applied if the regexp matches and the preceding rewritecond's match. If you put a L
flag, then no further rules will be applied, if that rule is.
In your case, the first rule is applied. The next rule is not, since the cond's don't apply. And then the last rule is applied.
精彩评论