How can I rewrite this nginx “if” statement?

Edit:

As Alexey Ten didn’t add a new answer, I’ll edit mine to give his better answer in this case.

if ($http_user_agent ~ "MSIE [67]\.")

Original answer:

Nginx doesn’t allow multiple or nested if statements however you can do this :

set $test 0;
if ($http_user_agent ~ "MSIE 6\.0") {
  set $test 1;
}
if ($http_user_agent ~ "MSIE 7\.0") {
  set $test 1;
}
if ($test = 1) {
  rewrite ^ ${ROOT_ROOT}ancient/ last;
}   

It is not shorter but it allows you to do the check and put the rewrite rule only once.

Alternative answer:

In some cases, you can also use | (pipe)

if ($http_user_agent ~ "(MSIE 6\.0)|(MSIE 7\.0)") {
  rewrite ^ ${ROOT_ROOT}ancient/ last;
}  

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)