The dash ('-') in .htaccess

那年仲夏 提交于 2019-12-11 00:35:37

问题


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|someotherfile) - [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) ?


回答1:


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.



来源:https://stackoverflow.com/questions/5276668/the-dash-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!