0

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]
jscott
  • 24,484
  • 8
  • 79
  • 100

1 Answers1

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.

Steve
  • 282
  • 1
  • 6