I want to redirect requests on two conditions using nginx.
This doesn't work:
if ($host = 'domain.com' || $host = 'domain2.com'){
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
}
What is the correct way to do this?
I want to redirect requests on two conditions using nginx.
This doesn't work:
if ($host = 'domain.com' || $host = 'domain2.com'){
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
}
What is the correct way to do this?
Here's a declarative approach:
another possibility would be
so it will redirect all to one specific but it's based on the usecase i guess
I had this same problem before. Because nginx can't do complex conditions or nested if statements, you need to evaluate over 2 different expressions.
set a variable to some binary value then enable if either condition is true in 2 different if statements:
The correct way would be to use a dedicated server for the redirect:
I think the easiest way to do it it's just use regular expression:
But it's good only when you have only strings; for complex logic, sure, it is not correct.