Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess regex, allow underscores

Here is our current regex:

RewriteRule ^share/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /v.php?v=$1&hash=$2 [L]

This isn't allowing underscores "_" - how do we get this to allow underscores?

Thank you

like image 777
Latox Avatar asked Aug 20 '26 17:08

Latox


2 Answers

You can shorten your regex like this as well. Now this will allow _ also. \w is shorthand for [a-zA-Z0-9_]

RewriteRule ^share/([\w-]+)/([\w-]+)/?$ /v.php?v=$1&hash=$2 [L]
like image 149
Narendra Yadala Avatar answered Aug 22 '26 17:08

Narendra Yadala


By adding _ to both expressions within the braces []:

RewriteRule ^share/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /v.php?v=$1&hash=$2 [L]
like image 37
Till Helge Avatar answered Aug 22 '26 17:08

Till Helge



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!