nginx redirect based on $request_uri
First of all, $request_uri
does not contain query arguments for the request.
There are two options:
- Use a return where you add
$args
after thelang
argument:
return 301 https://example.com?lang=fr&$args:
- 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;