Robert
Robert

Reputation: 925

Htaccess Regex Not Accepting underscore

I am trying to write a regex which accepts a username with an underscore.

I can get it to work without a underscore, but when I add an underscore it gives a site error 500

Here is my regex I am using:

RewriteRule ^Activation/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ activationcodes.php?u=$1&a=$2 [L]

When I add the _ it goes error 500 on the pages

RewriteRule ^Activation/([A-Za-z0-9-_]+)/([A-Za-z0-9-]+)/?$ activationcodes.php?u=$1&a=$2 [L]

Upvotes: 0

Views: 461

Answers (1)

tckmn
tckmn

Reputation: 59283

Add the underscore before the dash:

RewriteRule ^Activation/([A-Za-z0-9_-]+)/([A-Za-z0-9-]+)/?$ activationcodes.php?u=$1&a=$2 [L]

Otherwise it thinks you mean "0 to 9 to _," which is wrong.

You could also escape it (which would also make it more readable):

RewriteRule ^Activation/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-]+)/?$ activationcodes.php?u=$1&a=$2 [L]

Upvotes: 2

Related Questions