I am trying to redirect users to a new URL while preserving the URL query parameters. I'm trying this, which doesn't pass the URL params:
location = /api/redirects {
return 301 /api2/redirects;
}
https://example.com/api/redirects?param=1&anotherParam=10
=> https://example.com/api2/redirects
I also tried:
location = /api/redirects {
return 301 /api2/redirects$is_args$args;
}
$is_args$argsfix should work. Rather than relying on the browser, test it usingcurl -I http://example.com/api/redirectsreturndirective,rewriteone will preserve any existing query arguments:rewrite ^ /api2/redirects permanent;