zhuguowei
zhuguowei

Reputation: 8487

how to change query parameter name in Nginx

there is an api , e.g. http://example.com/v2/series/search?token=xxx&&limit=50&offset=0&databases=WORLD

one day some query parameter changed , e.g. databases ==> database, and cause the request is failed

response code:400 message:Filter('s) `databases` is(are) not supported.

so how to change query parameter name in Nginx location block?

I know how to append parameter by below way, but how to change parameter name?

location = /v2/series/search {
    set $args $args&foo=bar;
    proxy_pass xxx;
}

Upvotes: 1

Views: 854

Answers (1)

Ivan Shatsky
Ivan Shatsky

Reputation: 15662

Try this regex:

if ($args ~ (^|.*&)databases=(.*)) {
    set $args $1database=$2;
}

Should replace the databases query argument name to database regardless of whether it is at the beginning, in the middle or at the end of the query string.

Upvotes: 1

Related Questions