在.htaccess - 破折号('') [英] The dash ('-') in .htaccess

查看:130
本文介绍了在.htaccess - 破折号('')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特殊字符串 - (短线)的替代意味着没有替换,当你需要应用该规则同时保留原始URL不变是非常有用的。

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

所以:

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

这告诉了mod_rewrite离开网址不变,并退出处理规则如果请求的子目录或文件preFIX是那些在候补名单中的一个。 如果请求的子目录是在列表中,经此一所有的规则得到跳过。

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.

我不明白,为什么在这里我们需要几许?我们为什么要离开原来的URL不变。由于我们是在告诉这个规则是 [L] (最后一次),如果任何一个选项列表是这样,为什么我们需要 - (短线)?

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

推荐答案

这是唯一有有一个一致的语法。破折号明确告诉的httpd 不重写任何东西。考虑一下的httpd 倒觉得行,如果你删除了冲刺:

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]

在括号中的标志将是PTED作为重写目标间$ P $,你会重写所有匹配的网址为 [L] 代替。

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

这篇关于在.htaccess - 破折号('')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆