How does nginx use rewrite to add ?mode=test to all html, and only add it once?
阿神
阿神 2017-05-16 17:20:29
0
2
709
    location / {
            if($args *~ "mode=formal"){
                rewrite (.*) ? redirect;
                rewrite (.*) ?mode=test redirect;
            }
            else if($args [[不包含mode=test]]){
                rewrite ^/(.*).html$ /.html?mode=test redirect;
            }
            error_page 404 = @nodejs;
    }

I want to configure it in the above way, first judge $args, and then rewrite, I don’t know if it is possible.
And how should I write [[excluding mode=test]]?

renew

It has been tested and this does not work. $args cannot be used in the if condition. So how should this idea be implemented?

renew

I have tried both methods in the reply, and when I restart nginx, the same error will appear:

nginx: [emerg] unknown directive "if($arg_mode" in ....

and

nginx: [emerg] unknown directive "if($query_string" in ....

Is it because the if module is not installed?

阿神
阿神

闭关修行中......

reply all(2)
黄舟

if ( $arg_mode !~ \w+ ){
rewrite (.*) /index.html?mode=test redirect;
}

Ty80
location / {
if ($query_string !~ mode=test) {
    rewrite ^/(.*)\.html$ /$1.html?mode=test redirect;
}
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template