Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

apache - mod_rewrite urlencoding an already urlencoded query string parameter - any way to disable this?

We have some very basic mod_rewrite rules:

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

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

something.swf?param=value, it is redirected correctly to http://www.newdomain.com/something.swf?param=value

the problem is in this situation:

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

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

REDIRECTED TO

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

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

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)

and

something.swf?someparams...

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

should in fact read

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

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

as easy as that :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...