开发者

does mod_rewrite evaluate {REQUEST_FILENAME} after each rewrite rule?

Here is the case :

RewriteEngine On
RewriteBase /app/webroot/

RewriteRule ^(.*)$ $1 [QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %开发者_Go百科{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Does the RewriteConds for the second rule use the result of the first RewriteRule ?

For instance, if i request /onestaticfile.txt and that file actually exists in /app/webroot, how to be sure that the final url would be /app/webroot/onestaticfile.txt instead of /app/webroot/index.php?url=onestaticfile.txt ?


For instance, if i request /onestaticfile.txt and that file actually exists in /app/webroot, how to be sure that the final url would be /app/webroot/onestaticfile.txt instead of /app/webroot/index.php?url=onestaticfile.txt ?

The RewriteConds for the second rule will get evaluated. But since onestaticfile.txt exists, it will fail the !-f test and the second rule won't be applied (so final url will be: /app/webroot/onestaticfile.txt). Likewise, if onestaticfile.txt doesn't exist, the 2nd rule would get applied.

In either case, when the rule is applied, an internal redirect happens and the whole thing happens again with the rewritten URI. But the 2nd time around doesn't change the base URI (without the query strings) so nothing happens the second time around.

If you had an L in the square brackets of your first rule, the 2nd rule would never be applied because rewriting will always end on the first Rule.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜