nginx.conf redirect multiple conditions

前端 未结 6 1819
傲寒
傲寒 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:37

    Rewriting multiple domains to a single domain and avoiding a looping condition in the browser.

    server {
        listen       80;
        server_name  www.wanted_domain.com wanted_domain.com www.un_wanted_domain.com un_wanted_domain.com;
        if ($host = 'un_wanted_domain.com'){
           return 301 $scheme://www.wanted_domain.com$request_uri;
        }
        if ($host = 'www.un_wanted_domain.com'){
           return 301 $scheme://www.wanted_domain.com$request_uri;
        }
    

提交回复
热议问题