Home > database >  nginx rewrites with possible query
nginx rewrites with possible query

Time:12-10

I'd like a single nginx rewrite rule, hopefully in one line of code because I have to make a bunch of these, that can match and redirect either of these:

/short_url
/short_url?utm_source=email

without matching and redirecting:

/short_url/page.html
/short_url/page.html?utm_source=email

And if the query string exists, I want to pass it on.

I was hoping this would work, but no:

rewrite (?i)^/short_url /new_short_url$is_args$args permanent;

What's the secret sauce?

CodePudding user response:

URL params are always passed with rewrite, no need to explicitly declare them in new URL.

## /short_url
## /short_url?utm_source=email
rewrite ^/short_url(\?utm_source=email)?$ /new_uri
  • Related