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]
  • Please don't add "NEED HELP!!!111", we understand that by you posting here :) (sorry, don't know the answer)
    – Znarkus
    Sep 28, 2010 at 18:07
  • Sure Znarkus sry
    – user55536
    Sep 28, 2010 at 18:20
  • Can you use the code sample feature next time also, makes it much easier to read your example.
    – Steve
    Oct 2, 2010 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy