Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write nginx rewrite rule for replacing query param in query string

Tags:

nginx

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

like image 365
ricoshet Avatar asked Oct 18 '25 18:10

ricoshet


1 Answers

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;
   }

}
like image 94
Tarun Lalwani Avatar answered Oct 21 '25 10:10

Tarun Lalwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!