nginx redirect based on $request_uri

First of all, $request_uri does not contain query arguments for the request.

There are two options:

  1. Use a return where you add $args after the lang argument:

return 301 https://example.com?lang=fr&$args:

  1. Use a map:

In http level, you define the map:

map $args $redirargs {
    "~.+" $args&lang=fr;
    default lang=fr;
}

And then use

return 301 http://example.com$request_uri?$redirargs;