nGinx – rewrite question

Hi,
I'm fairly new to nginx and I'm trying to confirm my understanding here:

rewrite ^/(&!Api|Errors|Triage)/?(.*)$ https://$host$requesturi;

My understanding:
That's an "if" statement and it'll ignore the rewrite if it sees Api, Errors or Triage.

Question:
Am I missing anything? (am i just completely wrong?)

2 thoughts on “nGinx – rewrite question”

  1. Hi there.

    The regex question mark usually means the previous expression match is optional. In this case referring to the slash immediately before it. Therefore, an incoming uri could be `/Errorssomething` or `/Errors/something` and still build the two match groups `Errors` and `something`.

    The group match (in parenthesis) is looking for Errors or Triage, but not Api.

    Also, the variable `$requesturi` should probably be `$request_uri`. `$host$request_uri` isn’t a very useful rewrite since it will just write out exactly what came in on the original request.

    I think there may be other problems with this, but I can’t make assumptions about the use case.

    Reply

Leave a Comment