mod_rewrite urlencoding 一个已经 urlencoded 的查询字符串参数 - 有什么方法可以禁用它吗? [英] mod_rewrite urlencoding an already urlencoded query string parameter - any way to disable this?

查看:21
本文介绍了mod_rewrite urlencoding 一个已经 urlencoded 的查询字符串参数 - 有什么方法可以禁用它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些非常基本的 mod_rewrite 规则:

We have some very basic mod_rewrite rules:

RewriteRule ^something.swf$ http://www.newdomain.com/something.swf [R=302,L]

mod_rewrite 似乎完成了它的工作,如果用户正在访问:

mod_rewrite seems to do its job, and if the user is accessing:

something.swf?param=value,正确重定向到 http://www.newdomain.com/something.swf?param=value

问题出在这种情况下:

www.olddomain.com/something.swf?param=URL_ENCODED_VALUE

最终发生的是 mod_rewrite 自行重新对查询字符串参数进行 urlencode

what ends up happening is mod_rewrite takes it upon it self to re-urlencode the query string param

所以用户最终得到的是:

so what the user ends up with is:

www.olddomain.com/something.swf?param=URL_ENCODED_VALUE

重定向到

www.newdomain.com/something.swf?param=URL_ENCODED_VALUE_OF_URL_ENCODED_VALUE

所以我们最终得到一个双 urlencoded 值.赞!

so we end up with a double-urlencoded value. boourns!

虽然我明白我们可以为此制定一个 \?(.*) ... ?$1 规则,但我认为必须有一种方法可以告诉mod_rewrite 不是对查询字符串参数进行 urlencode...我们希望避免使用 2 条规则,因为有效路径是:

While I do understand we could make a \?(.*) ... ?$1 rule for this, I am thinking there must be a way to tell mod_rewrite NOT to urlencode the query string params... we would like to avoid using 2 rules since valid paths are:

something.swf (no query string)

something.swf?someparams...

是的,理想情况下...只需告诉 mod_rewrite:请不要对查询字符串参数进行 urlencoding...只需通过 R=302 直接传递到新 URL.

so yea, ideally... just tell mod_rewrite: please, no urlencoding of query string params... just direct passthru to the new URL via R=302.

推荐答案

实现这一点的方法是通过 NE(无转义)参数.

the way to accomplish this is via the NE (no escape) paramater.

RewriteRule ^something.swf$ http://www.newdomain.com/something.swf [R=302,L]

其实应该读

RewriteRule ^something.swf$ http://www.newdomain.com/something.swf [R=302,NE,L]

这将强制 mod_rewrite 保留所有查询字符串值原样,而不进行任何编码/转义.

this will force mod_rewrite to leave all query string values as they are, without doing any encoding / escaping.

就这么简单:)

这篇关于mod_rewrite urlencoding 一个已经 urlencoded 的查询字符串参数 - 有什么方法可以禁用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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