0

Looking to see if there is a better way to redirect a query string other than using if in this situation.

Example URL: http://foo.com/?p=123 to http://foo.com/new

Current using if:

location / {
  if ($args ~ p=123) {
  rewrite ^ https://foo.com/new? permanent;
  }
}

1 Answer 1

2

You should check the actual argument value, so that you don't accidentally match things like op=1234 when you wanted to match p=123.

For performance reasons, you should also use return instead of rewrite unless you actually need regex matching.

For example:

if ($arg_p = 123) {
    return 301 https://example.com/new;
}

(And of course, return is perfectly fine to use with if.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .