Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex pattern does not support # symbol

Tags:

regex

nginx

I use regex in Nginx configs to capture file urls but if the file URL contains the # symbol, regex pattern will not capture it.

Here is the part of nginx config.

location ~ ^/p/(?<secure>[\w\-=]+,\d+),(?<user>[^/]+)(?<file>/.*)$ {

}

An example file URL causing the error because it has # symbol in it.

http://mydomain.com/p/KPFHELPFAQrc3rUPIUS7Cg,1401267921,1/4962/Ubuntu#6 (DVD-ISO)/Ubuntu-12-04.iso
like image 489
Naveen Gamage Avatar asked Apr 15 '26 07:04

Naveen Gamage


1 Answers

You need to change # to %23 in url:

http://mydomain.com/p/KPFHELPFAQrc3rUPIUS7Cg,1401267921,1/4962/Ubuntu%236 (DVD-ISO)/Ubuntu-12-04.iso

Here is complete list of URL Escape Characters

like image 200
Farshid Ashouri Avatar answered Apr 16 '26 20:04

Farshid Ashouri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!