1

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
2
  • 2
    please post the code of your .htaccess (we can't help you until you do ...) Commented Aug 5, 2012 at 13:42
  • 1
    @Yazmat I have provided the codes..I had to edit the question. Thanks Commented Aug 5, 2012 at 14:19

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks poncha (yeah the dash should always be the last)
thanks for the answer. At least I have learnt that today. I tried the expression RewriteRule ^([a-zA-z0-9_-.]+)$ community/profile.php?_username=$1 But it returned 500 Server Not Found Error. I then had to change it this way RewriteRule ^([.a-zA-z0-9_-]+)$ community/profile.php?_username=$1 and it did work. @Poncha thanks too for the edit
poncha and @Yazmat please what is the logic or reason for the dash being the last and why did the dot being the last returned the 500 Internal Server Error?
0
  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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.