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]]?
It has been tested and this does not work. $args cannot be used in the if condition. So how should this idea be implemented?
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?
if ( $arg_mode !~ \w+ ){
rewrite (.*) /index.html?mode=test redirect;
}