How to redirect domain aliases via Nginx?

  • 0
    The domain has multiple aliases.
    server_name site1.ru site2.ru site3.ru

    I need to redirect site1.ru/page for example to google.com
    And site2.ru/landing Redirect to Yandex.ru

    if ($http_host = 'site1.ru') {
        rewrite ^(.*) https:/google.com permanent;
      }
    
    if ($http_host = 'site2.ru') {
        rewrite ^(.*) https://yandex.ru permanent;
      }


    Is there another option to get by with one block?
    Nginx Emma Ramos, Aug 6, 2019

  • 1 Answers
  • 0
    Why go for one block if your processing is different? Other things being equal, it is better to make separate server blocks than crutches with ifs.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!