0

On my server I am using this .htaccess to remove the .PHP extension:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

And it works fine, /about goes to the about.php page and /contact to the .contact.php file. However I have a projects.php and a projects folder so the hyperlink redirects to the folder index. I understand I could simply rename either the php or folder and solve the problem, but if I have subfolders in the projects folders, I won't be able to keep the URL as /projects/photography Here is an image to help explain: https://i.stack.imgur.com/TKjEF.png

1 Answers1

1

Try

DirectorySlash Off

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/projects$ [NC]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

It should work with DirectorySlash off, but see caveats. If you don't like them you are better off renaming projects.php

Community
  • 1
  • 1
Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31