Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top