nginx.conf redirect multiple conditions

前端 未结 6 1815
傲寒
傲寒 2021-01-30 03:46

I want to redirect requests on two conditions using nginx.

This doesn\'t work:

  if ($host = \'domain.com\' || $host = \'domain2.com\'){
    rewrite ^/(         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 04:24

    I think the easiest way to do it it's just use regular expression:

    if ($host ~ "domain.com|domain2.com") {
        rewrite ^/(.*)$ http://www.example.com/$1 permanent;
    }
    

    But it's good only when you have only strings; for complex logic, sure, it is not correct.

提交回复
热议问题