0

I have a website where users register using a username but my RewriteRule only works on one-name usernames and two-name usernames that are separated by an underscore or hyphen but if you use an @ sign before your username or you use a space,it doesn't work e.g if one registers using 'Tom', 'TomClark', 'Tom-Clark' or 'Tom_Clark' they can be able to go to their profile page but if they register using 'Tom Clark' or '@Tom Clark',they get Error 404 object not found.I want my RewriteRule to recognise spaces and @ sign.

Here is my .htaccess page:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1 
Henry
  • 1
  • `[a-zA-Z0-9_-@ ]` add them to your character class – CJD Sep 13 '15 at 16:27
  • @CJD I have tried that but am getting "Server error! The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. If you think this is a server error, please contact the webmaster. " – Henry Sep 13 '15 at 16:36
  • try replacing the space with `\s` – CJD Sep 13 '15 at 16:39
  • @CJD the error is still there. By the way I was using preg_replace to replace space with _ but I realized that was confusing users when they tried to login later – Henry Sep 13 '15 at 16:43
  • It worked when I did this RewriteRule ^([a-zA-Z0-9\s_-]+)$ profile.php?u=$1 RewriteRule ^([a-zA-Z0-9\s_-]+)/$ profile.php?u=$1 – Henry Sep 13 '15 at 17:16
  • Thanks 4 giving me an idea of what to do – Henry Sep 13 '15 at 17:19

0 Answers0