How to remove a request parameter of the URL from NGINX

I want to remove a query (page=1) parameter from the request URL. I just want to remove that query parameter from the URL if its present. It can be located as a first query param or the last or the middle.

Below are the examples of the possible URL :

www.abc.com/category?page=1
www.abc.de/category/deep-category?other=params&page=1
www.abc.com/category/deep-category?other=params&page=1&another=param

After removing this page=1 param, the URLs should look like this:

www.abc.com/category
www.abc.de/category/deep-category?other=params
www.abc.es/category/deep-category?other=params&another=param

Generally you can use the following:

if ($args ~ (.*)(^|&)page(?:=[^&]*)?(\2|$)&?(.*)) {
    set $args $1$3$4;
}

Using the above regex you can remove a query argument no matter it is at the beginning, in the middle or at the end of the query string.

However on some configurations the backend can rely on the $request_uri variable which won't be changed with the above configuration fragment.