When I want to match a URL with spaces in it, the spaces may be encoded as %20
or +
. In order to match this in an Nginx regex, what pattern do I need to use?
Does Nginx pass the URL through as-is?
(?:%20|\+| )
or, does Nginx do some unquoting or unescaping first?
(?:\+| )
or is +
normalized?
Though I didn't find any references in the Nginx documentation with a quick look, from my testing, Nginx normalizes HTTP codes as unicode such that '%20' is matched with a '\s'. '+' is already in unicode and doesn't need to be normalized.
Eg. /route/the%20test
Should match with (?:\s)
However, I tend to lean on the safer side and use something like: (?:(\s|\%20))
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