URL encoding for nginx rewrites

Hello everyone.
I am using a rewrite similar to below

location /home {
    rewrite ^/(.*) https://mysite.com/homepage/?next=/redirectionurl

redirect;
}

The issue is that nginx is not encoding the URL before it redirects.

So this is failing at the server that is receiving this request.

Can someone help me in encoding the rewritten URL.

Thanks a lot in advance

Posted at Nginx Forum: