开发者

Apache RewriteRule, - (dash) as substitution

I often see in PHP MVC applications an Apache RewriteRule that looks like this:

RewriteRule ^.*$ - [NC,L]

The Apache docs for the RewriteRule directive states:

A dash indicates that no substitut开发者_JS百科ion should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

So from what I gather, you can use this to transform a path using a flag i.e [NC] for the RewriteRules to follow?

Could someone please explain this dash RewriteRule a little better?


See this answer:

mod_rewrite: what does this RewriteRule do?

It essentially means "do nothing if the previous RewriteConds match". The next RewriteRule(s) will instead do something else when the RewriteConds don't match. In the case of the post i linked you to, the next RewriteRule rewrites the url including "index.php".


I know this is kinda old, but it basically says "Hey, i might wanna use Rewrite, but for urls that match the above RewriteCond(s), leave it be and stop."

EX:

# If file or directory exists, we wanna send them there
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

# Otherwise, use our smart page handler!
RewriteRule ^(.*)\.php$ virtualPage.php?page=$1 [L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜