4

folks!

We have following http request:

http://example.com/foo?redirect_uri=http%3A%2F%2Fexample.com%2Fbar

We want to replace redirect_uri from "example.com" to "example.net".

How to do it?

Thanks

1 Answer 1

5

You need to do it like this

location /foo {
   if ($args ~* "(.*)(example\.com)(.*)") {
       set $args "$1example.net$3";
       return 301 $scheme://$host$uri$is_args$args;
   }

}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this also worked for me, but only after I added a try_files statement under the if-block to process the new URI. The location string matches both!
Missing a ? between $uri and $args should be return 301 $scheme://$host$uri?$args;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.