Making nginx check parameter in url

arguments, nginx, parameters

Solution

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`.

Problem

I want to check if a parameter is present in a url in nginx and then rewrite.How can i do that? For e.g if url is `http://website.com/?mobile` then redirect user to `http://m.website.com`

Original source