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
.