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.

This script works perfect it forces the trailing slash and hides the .php extension

BUT! it does not redirect people going directly to the .php extension.

How can I also force people going directly to the file.php to /file/

RewriteEngine On
RewriteRule ^(.*)/$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.mysite.com/$1/ [R=301,L]
share|improve this question
    
Please don't add "NEED HELP!!!111", we understand that by you posting here :) (sorry, don't know the answer) –  Znarkus Sep 28 '10 at 18:07
    
Sure Znarkus sry –  user55536 Sep 28 '10 at 18:20
    
Can you use the code sample feature next time also, makes it much easier to read your example. –  Steve Oct 2 '10 at 11:50

1 Answer 1

I think there might be a few errors here:

RewriteCond %{REQUEST_FILENAME} !-f

This declares to the next rule should only occur if the filename is not a file, your .php is a file so that would fire false.

This should work, or at least set you on your way:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [L]

!-d ensures that the requested path is not a directory; this solves potential issues like images/ leading to images.php instead of your images directory.

share|improve this answer

Your Answer

 
discard

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