mod_rewrite NE 标志 - 什么时候对 URL 中的特殊字符进行编码有帮助?
我一直在查看 mod_rewrite 中的 [NE]
(noescape) 标志。经过一番思考,我无法弄清楚什么情况下我不想想要使用该标志。这意味着,在几乎每个 RewriteRule
中保持启用该标志似乎最有帮助。在某些情况下,不调用此标志给我带来了问题。
我处理的大多数规则都是 HTTP 重定向 ([R]
),而不是传递。
有人会透露一下什么时候让 mod_rewrite 对 URL 进行编码有帮助吗?
启用此标志通常是一种好的做法,还是使用允许 mod_rewrite 转义这些特殊字符的默认行为?为什么?
I've been looking at the [NE]
(noescape) flag in mod_rewrite. After some thought I couldn't figure out a situation when I would NOT want to use the flag. Meaning, it seems most helpful to keep the flag enabled in almost every RewriteRule
. Not invoking this flag has caused me problems in a few circumstances.
Most of the rules that I deal with are HTTP redirects ([R]
), rather than passing through.
Would someone shed some light as to when it is helpful to have mod_rewrite encode the URL?
Is it generally good practice to enable this flag, or use the default behavior of allowing mod_rewrite escape these special characters? Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看 mod_rewrite 的源代码,您会注意到,如果启用了
noescape
,它会设置一个proxy-nocanon
标志。在修订版中该行首次添加的位置,还包含以下注释:
接下来,如果您阅读 mod_proxy 文档,您将看到以下提及
nocanon
的内容:我可能是错的,但这对我来说意味着在 mod_proxy 中使用
nocanon
(以及在 mod_rewrite 中扩展noescape
)具有潜在的安全影响。这可以解释为什么它默认被禁用,即使在大多数情况下启用它似乎更有用。If you look at the source code for mod_rewrite, you'll notice that it sets a
proxy-nocanon
flag ifnoescape
is enabled.In the revision where that line was first added, it also included this comment:
Following on from that, if you read the mod_proxy documentation, you'll see the following mention of
nocanon
:I'm may be mistaken, but that implies to me that the use of
nocanon
in mod_proxy (and by extensionnoescape
in mod_rewrite) has potential security ramifications. That would explain why it is disabled by default, even thought it seems like it would be more useful to have it enabled in most cases.当您将请求 URL 添加为授权签名的一部分时,
[NE]
标志非常有用。我刚刚遇到一个错误,授权在 .htaccess 关闭时有效,但在 .htaccess 打开时无效。事实证明,原因是重定向对最终出现在 php
$_GET
参数中的项目进行了 url 编码。为了解决这个bug,我将:改为
(授权签名由很多东西组成,其中之一就是请求url)
The
[NE]
flag is extremely useful when you are adding the request url as part of - let's say - an authorization signature.I just had a bug where authorization was working with .htaccess off but not with it on. It turned out the cause was that redirection was url encoding the items that ended up in the php
$_GET
parameter. To solve the bug I changed:to
(the authorization signature is composed of many things, one of these is the request url)