Htaccess QUERY_STRING urldecode

I have a problem with .htaccess and QUERY_STRING.

I am trying to redirect a url using htaccess which 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 REQUEST_URI to redirect the url, and everything works fine since REQUEST_URI is urldecoded by default in htaccess.

However, when I send a link to Hotmail, Hotmail urldecodes slashes and a question mark. The result is as follows:

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

So, htaccess takes the link and tries to redirect it, but because of the question mark, htaccess "thinks" everything that is behind the question mark is QUERY_STRING.

Problem: apache2 is not urldecode 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 QUERY_STRING or use the full requested url (urlendcoded or urldecoded), including the part after the question mark

Thanks in advance!

Greetings

+6
source share
1 answer

You do not need to add [QSA] to the rewrite rule to force htaccess to also encode the query string.

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

0
source

Source: https://habr.com/ru/post/896225/


All Articles