0

I have an nginx location redirect set up to redirect /my_route to a coming soon page, but allow /my_route?db=preview to pass through to the proxy server.

location /my_route {
  if ($arg_db != "preview") {
    rewrite ^ /coming-soon/ last;
  }
  <other location config for when db == preview>
}

I want to add an additional layer of complexity, to support multiple languages for the coming soon page.

Config that breaks nginx, but give you the idea:

location /my_route {
  if ($arg_db != "preview") {
    if ($arg_lang == "es") {
      rewrite ^ /coming-soon/index_es.html last;
    }
    rewrite ^ /coming-soon/ last;
  }
  <other location config for when db == preview>
}

I know that if is evil, so I'm happy to move away from using if, if that's what is needed, but I don't know which direction to look. I just know nginx doesn't support && statements, or nested if statements.

1 Answer 1

1

You could use a map to eliminate the inner if block.

For example:

map $arg_lang $mylang {
    default   /;
    es        /index_es.html;
}
server {
    ...
    rewrite ^ /coming_soon$mylang last;
    ...
}

See this document for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.