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?)
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.
I’m not familiar with a &! modifier for a capture group, but you can use one of several online regex testers to verify your regex. Just make sure you’re setting it to PCRE.
https://debuggex.com/
https://regex101.com/