Apply URL encoding during rewrite rule

Ed W lists at wildgooses.com
Wed Feb 1 19:24:56 UTC 2012


Hi, I need to do a redirect and pass the old URL to the redirected 
destination. How might I achieve this using nginx?

I tried a rewrite rule simply:
     rewrite ^/(.*) 
$scheme://$server_addr/?redirect_to=$scheme://$host$request_uri redirect;

However, this simply appends the old url verbatim on the end of the 
?redirect_to parameter

I tried a few other variables, but I don't see any way to ask Nginx to 
url-encode something for me?

Any other thoughts on ways to achieve the desired effect?  The 
redirected to destination is a web app under my control - we could proxy 
the initial request to the web app and have it generate the redirect, 
but I was hoping to decouple things

Thanks for any thoughts

Ed W



More information about the nginx mailing list