I have this code somewhere in my .htaccess file:

RewriteRule /user/([a-zA-Z0-9]+) /iduser.php?username=$1

It should make /user/oliolio request iduser.php?username=oliolio, however it doesn't work. :(

Do you know why?

link|improve this question
Can you confirm that rewrite rules are working over all, too? – Gavin C Jun 2 '11 at 11:32
feedback

migrated from stackoverflow.com Jun 1 '11 at 17:45

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 2 down vote accepted
RewriteRule ^(.*)/user/([a-zA-Z0-9]+)$ /iduser.php?username=$2 [L]

Or if its just yourdomain.com/user/ollio then

 RewriteRule ^user/([a-zA-Z0-9]+)$ /iduser.php?username=$1 [L]

Make sure RewriteEngine On is set

link|improve this answer
Appreciate that you kept the asker's character/number restriction in the regex, but might want to simplify to using [a-z0-9] and adding the "nocase / NC" directive – Gavin C Jun 2 '11 at 11:30
feedback

Have your rule like this:

RewriteRule ^user/(.*)/?$ /iduser.php?username=$1 [QSA,NC,L]

Apache strips out leading slash / that's why your rule is not working.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.