user2570937
user2570937

Reputation: 852

How do I allow numbers in htaccess rewrite rule?

I have a htaccess setup like so:

RewriteRule ^([A-Za-z_]+)$ profile.php?name=$1 [NC,B,QSA]

it works fine however it doesn't work when the parameter has a number in it.

also is it possible to allow periods and commas?

What can I change?

Upvotes: 0

Views: 310

Answers (1)

anubhava
anubhava

Reputation: 784908

Change the regex:

RewriteRule ^([0-9A-Za-z_]+)$ profile.php?name=$1 [L,QSA]

OR even better

RewriteRule ^(\w+)/?$ profile.php?name=$1 [QSA,L]

Since \w is same as [0-9A-Za-z_]

OP's comment:

is there a way to let it use periods and commas as well?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w,.]+)/?$ profile.php?name=$1 [QSA,L]

Upvotes: 3

Related Questions