0

I want to redirect from nginx to a URL that is send as an argument in the encoded form.

location /v1/redirect {
        access_log /var/log/nginx/redirect/access.log main;
        error_log /var/log/nginx/redirect/error.log;
        return 302 $arg_dest;
        }

When I am passing unencoded URL for e.g. https://ex2.example2.com/v1/redirect?dest=https://ex1.example2.com It is working fine.

But on encoding dest argument as https://ex2.example2.com/v1/redirect?dest=https%3A%2F%2Fex1.example2.com. I am getting status code 304 and my URL is changing to https://ex2.example2.com/v1/https%3A%2F%2Fex1.example2.com.

Can someone help me identify what I am doing wrong, Is there a way to possibly URL decode arg_dest before passing to return? Thanks

lifeisshubh
  • 513
  • 1
  • 5
  • 27

1 Answers1

0

njs can be used to solve the above problem. Take a look at https://github.com/xeioex/njs-examples/blob/master/conf/http/decode_uri.conf and https://github.com/xeioex/njs-examples/blob/master/njs/http/decode_uri.js to solve the above problem.

lifeisshubh
  • 513
  • 1
  • 5
  • 27