开发者

The dash ('-') in .htaccess

Special string - (dash) in Substitution means no substitution and is useful when you need to apply the rule while leaving original URL untouched.

So:

RewriteRule ^(somefile|somedir|s开发者_如何转开发omeotherfile) - [L]

This tells mod_rewrite to leave the URL unchanged and quit processing rules if the requested subdirectory or file PREFIX is one of those in the alternate list. If the requested subdirectory is in the list, all the rules after this one get skipped.

I don't understand why here we need the dash? Why we need to leave the original URL untouched. Since we are telling that this rule is the [L] (last) if any of the list options is the case, why do we need the - (dash) ?


It's only there to have a consistent syntax. The dash explicitly tells httpd not to rewrite anything. Consider what httpd would think of that line if you removed the dash:

RewriteRule ^(somefile|somedir|someotherfile) [L]

The flag in brackets would be interpreted as the rewrite target and you would rewrite all matching URLs to [L] instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜