views:

914

answers:

1

Hi, I have the following bit of code in my htaccess that will allow a users ID to only be alphanumeric and include underscores and hyphens:

RewriteRule ^([A-Za-z0-9_-]+)$ profile.php?ID=$1 [QSA,L]

I've recently imported over 1000 usernames from a social networking platform that allowed usernames to contain special characters, but this new platform I've migrated the usernames into won't.

How could I edit this regex to include the following special characters:

[ ] = , ? & @ ~ { } + ' . * ! ™ ` (and spaces).

Any help would be much appreciated.

+1  A: 
RewriteRule ^([\[\]=,\?&@~\{\}\+'\.*!™` A-Za-z0-9_-]+)$ profile.php?ID=$1 [QSA,L]

Fairly self-explanatory. Just include all the characters, with escapes if they're regex special characters.

Matthew Flaschen
This is not entirely correct - character classes have a different definition of what are special characters within a class compared to what are special outside of it - some of those \ are redundant.
Peter Boughton
Yes, redundant, but still correct. And easier to move outside the class if needed.
Matthew Flaschen