T
T
Templar3d2020-07-21 22:08:44
Nginx
Templar3d, 2020-07-21 22:08:44

How to make an nginx redirect with a condition?

How to:
if example.com/static.* then 404
otherwise
return 301 https://myexample.com$request_uri ;
Trying to describe how in nginx:

server {
if ($host = example.com) {
  if ($request_uri = "static.*") { return 404 ; }
  }
if ($host = example.com) {
    return 301 https://myexample.com$request_uri;
    }
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-07-21
@ky0

Make a location with the necessary expression instead of if - then the redirect to the error will work only inside it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question