I currently have PHP scripts that work properly, being called like this:

  • www.example.com/user.php/paul
  • www.example.com/tag.php/food

I'm having trouble getting .htaccess to rewrite properly. I'm trying to achieve this:

  • www.example.com/user/paul
  • www.example.com/tag/food

So far, I can get it to redirect /user to /user.php, but the /paul is lost; breaking my script.

My current .htaccess looks like this:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /([^.\ ]+\.)+php(\?[^\ ]*)?\ HTTP
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]
RewriteRule ^([^/]+/)*index/?$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.example.com/$1 [R=301,L]
RewriteCond $1 !^([^.]+\.)+([a-z0-9]+)$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*[^/])$ /$1.php [L]

Please help. Thanks! Paul

link|improve this question
feedback

1 Answer

RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

Should look like:

RewriteRule ^(.+)\.php/(.+)$ http://www.example.com/$1/$2 [R=301,L]

The items in parenthesis can be referenced in the target as $N for each regex in parenthesis you have.

link|improve this answer
still doesn't work, sorry – Paul Jun 8 '11 at 0:33
Do you mean you want user input http://example.com/user/paul to be presented to httpd as http://example.com/user.php/paul? – James Jun 8 '11 at 1:29
yes, that's what needs to happen – Paul Jun 8 '11 at 5:22
any other ideas? – Paul Jun 8 '11 at 20:57
What about this? RewriteRule ^(.+)/(.+)$ http://www.example.com/$1.php/$2 [L] – James Jun 9 '11 at 22:15
feedback

Your Answer

 
or
required, but never shown

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