Reputation: 1020
I need to remove a certain query param from the request URI, before redirecting the user from domain1.com
to domain2.com
. The query param is migrate
.
So from this URL:
domain1.com/check?migrate=true&uuid=1821
I want to take the user to this URL:
domain2.com/check?uuid=1821
There can be a lot more query params, and I want to keep them all except migrate
Upvotes: 1
Views: 676
Reputation: 49672
You will need to apply a regular expression to a variable that contains the entire query string - so either $request_uri
or $args
are possible candidates.
To redirect just /check
, you could use:
location = /check {
if ($args ~* ^(.*&)?migrate=[^&]*(&(.*))?$)
return 301 http://domain2.com$uri?$1$3;
}
return 301 http://domain2.com$uri?$args;
}
See this caution on the use of if
.
Upvotes: 1