In my default site config file, I have the following redirect to enforce https :
server {
listen 80;
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
I want to add a subdomain, but to redirect it to the site wit a parameter. e.g. fr.example.com --> https://example.com?lang=fr
If I do:
return 301 https://example.com$request_uri&lang=fr;
It will add on '&lang=fr' whether there are any other parameters in $request_uri or not.
How do I conditionally define '?' or '&', based on the content of $request_uri ?
I tried the following:
server {
listen 80;
server_name fr.example.com;
if ($request_uri ~ ""){
return 301 https://example.com?tlang=fr;
}
return 301 https://example.com$request_uri&tlang=fr;
}
but like this the site failed all-together.
Thanks