htaccess QUERY_STRING urldecode

折月煮酒 提交于 2019-12-23 09:30:07

问题


I have a problem concerning .htaccess and QUERY_STRING.

I try redirecting an URL with my htaccess that looks like this:

http://mydomain.tld/out/http%3A%2F%2Fotherdomain.tld%3Fparam%3D0

to

http://otherdomain.tld?param=0

I use RewriteCond and RewriteRule with the REQUEST_URI to redirect the url and everything works fine since REQUEST_URI is urldecoded by default in the htaccess.

However, when I email the link to Hotmail, Hotmail urldecodes the slashes and the question mark. The result looks like this:

http://mydomain.tld/out/http%3A//Fotherdomain.tld?param%3D0

So htaccess takes the link and tries to redirect it but due to the question mark the htaccess "thinks" everything behind the question mark is a QUERY_STRING.

The problem: apache2 doesn't urldecode the QUERY_STRING. So what happens is that htaccess redirects to

http://otherdomain.tld?param%3D0

which will fail.

So my question is:

How can I tell htaccess to either urldecode the QUERY_STRING or use the full requested url (either urlendcoded or urldecoded) including the part after the question mark

Thanks in advance!

Cheers


回答1:


You need not add [QSA] to your rewrite rule to force htaccess to encode query string too.

http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html



来源:https://stackoverflow.com/questions/7246497/htaccess-query-string-urldecode

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