How to use .htaccess to redirect to an url that includes a query parameter
Posted
by wbervoets
on Stack Overflow
See other posts from Stack Overflow
or by wbervoets
Published on 2010-05-17T20:49:15Z
Indexed on
2010/05/22
7:20 UTC
Read the original article
Hit count: 180
.htaccess
|mod-rewrite
Hi guys,
I've been struggling with a redirect where the final URL includes a query parameter that is an URL. It seems htaccess is escaping some characters.
Here is my htaccess:
Code:
RewriteRule ^mypath http s://www.otherserver.com/cookie?param1=123&redirectto=http://otherserver2.com/¶m2=1 [L,R=302]
First, if I put
Code:
http s://www.otherserver.com/cookie?param1=123&redirectto=http://otherserver2.com/¶m2=1
in my browser address bar, www.otherserver.com will do its thing and then redirect to otherserver2 (including the ¶m2=1 which is a parameter of that URL and not of the URL otherserver.com) That's the behaviour I need :-)
Now when I try to use the htaccess redirect from my site: http://mysite/mypath; the behaviour is not the same then putting the same URL in the browser address bar; it now tries to redirect to http ://otherserver2.com/ (no param2=1 anymore). (ps: otherserver1 and otherserver2 are not under my control.)
I've tried escaping the redirectto parameter in my htaccess, like below, but it didn't work either:
Code: http s://www.otherserver.com/cookie?param1=123&redirectto=http%3a%2f%otherserver2.com%2f%3fparam2%3d1
Because then my browser tries to go to httpotherserver.com (all special characters are gone)
In the end I would like to see http ://mysite/mypath to show the contents of
Code: http s://www.otherserver.com/cookie?param1=123&redirectto=http://otherserver2.com/¶m2=1
(preferred solution) or do a redirect to that URL.
I hope my message is not to confusing, I hope someone can help me out; as I've already spent hours on this :-)
© Stack Overflow or respective owner