I have the following mod_rewrite rules set up:

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

This works fine, allowing me to use "nice" URIs (like www.mysite.com/about instead of www.mysite.com/about.php.

However, when I have both a directory and a file with the same name (for example /products and products.php, this breaks as apache just redirects to the directory. Is there a way to fix this?



You can remove RewriteCond %{REQUEST_FILENAME} !-d, but that's going to effectively disable your ability to browse directories or to load a DirectoryIndex page.

  • That does not seem to have any effect on my apache behaviour. I just took out that line completely, but it is still indexing the folder contents instead of going for the php file.
    – Goro
    May 18 '11 at 17:45

Your Answer

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

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