Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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.

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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