Right now I’m using this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ profile.php?userName=$1 [L]
This works for normal cases without spaces or underscores, etc… just the basics.
I need it to be pretty open to characters though – such as John_doe john-doe john doe.
I’ve tried a lot of other Regex’s, but I can’t seem to get one that works for everything. Much appreciate any help!
Thanks.
The
.character will match any single character:Note the use of this regex is discouraged because of character encoding purposes (and SEO as well, but I don’t know if it’s relevant to you). It’s always better to have addresses containing only lower case alphanumeric characters and dashes (
-).For more info about mod_rewrite regex, see this link.