Nginx uses the PCRE engine for evaluating regular expressions, the documentation state that /
delimiter is not used so we don’t have to escape the forward slash /
in an URI as we may do in a standard regex. An example of a valid nginx regex is location ~* /myapp/.+\.php$
BUT the following code is escaping the forward slash
location ~ ^\/(?:index|core\/ajax\/update|ocs\/v2|ocm-provider\/.+)\.php(?:$|\/)
What does \/
exactly mean in that context and why is it needed when the documentation says otherwise?
While Nginx does not require escaping the forward slash /
it does not either deny escaping it like we could escape any other character.
The first purpose of the regex special character \
is meant to escape the next character and thus nginx is just translating/matching \/
to /
like it would translate/match \j
to literal j
(the example have no purpose never the less \j
match literal j
).
One purpose of escaping forward slashes in the context of nginx could be for code portability.
Note that \
followed by a character have probably a different meaning than just escaping the followed char, a complete list is available here
Source: @monkeyzeus and @richard-smith comments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With