Dimgba Kalu
Dimgba Kalu

Reputation: 165

Issue with htaccess URL rewriting

I had successfully re-written almost all my urls from the old form to fine url using .htaccess rules. But I have a problem with some of the address formats

e.g example.com/myusername works fine while example.com/my.username throws back a 404 page not found

Note: my.username is a valid username in my database. Please how do I resolve this issue

Update: this is the complete code on the .htaccess file

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

#ErrorDocument 404 example.com

RewriteEngine on

RewriteRule ^(.*)\.htm$ $1.php [nc]

RewriteRule ^([a-zA-z0-9_-]+)$ community/profile.php?_username=$1

Upvotes: 1

Views: 142

Answers (2)

walrii
walrii

Reputation: 3522

  1. You need to not apply both rules if the first rule matches. Add the L flag. Without it, "abc/def.htm" will become "community/profile.php?_username=abc/def.php".
  2. The second rule is missing . as an allowable character.
  3. (probably) You want parameters kept for both rules. Add the QSA flag.

Resulting in

RewriteRule ^(.*)\.htm$ $1.php [nc,L,QSA]

RewriteRule ^([a-zA-z0-9_.-]+)$ community/profile.php?_username=$1 [L,QSA]

Upvotes: 0

Oussama Jilal
Oussama Jilal

Reputation: 7739

Your issue is that you didn't include the dot (.) in the regular expression in this line (since my.username contains a dot) :

RewriteRule ^([a-zA-z0-9_-]+)$ community/profile.php?_username=$1

Change it to this :

RewriteRule ^([a-zA-z0-9_.-]+)$ community/profile.php?_username=$1

Note that any character that may be in the username you must add to the regular expression (for now it supports alphanumerics, underscore, dash and dot).

Upvotes: 2

Related Questions