I need some .htaccess code that will treat extensionless files as PHP files.
Suppose the visitors visits www.mywebsite.com/dir1/dir2/file.name
, it will
You can write a rewriting rule which only takes into effect if the requested file doesn't exists.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(.*)$ $1.php [L]
You should have a look at Apache's Options directive, most specifically the http://httpd.apache.org/docs/2.0/content-negotiation.html option which you can include in your .htaccess file and will do just that.
Add to your .htaccess
:
Options +MultiViews
Ok, the answer was a combination of answers. I needed to add Options +MultiViews
in my Apache configuration. Then I extend Andrews
answer to the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L]
Regards and many thanks! Kevin