Making nginx check parameter in url

If you know you have only 1 parameter {{variable}} to switch, you can detect if exist like this

if ($request_uri ~ '\?{{variable}}') {
    ...
}

for example

if ($request_uri ~ '\?mobile') {
    return 302 https://m.example.com;
}

Also I suggest consider use this redirection

http://{{domain}}.{{tld}}/mobile -> http://m.{{domain}}.{{tld}}

location ~ '/mobile'
    return 301 'https://m.{{domain}}.{{tld}}';
}

for example

location ~ '/mobile'
    return 301 'https://m.example.com';
}

You better use http://example.com/?mobile=1 (argument with value). In this case checking is simple:

if ($arg_mobile) {
    return 302 http://m.example.com/;
}

Checking for argument existance is usually done with regexp like if ($args ~ mobile) but it's error-prone, because it will match mobile anywhere, e.g. http://example.com/?tag=automobile.