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 first look the file dir1/dir2/file.name
exists and if it not exists, it will look for dir1/dir2/file.name.php
(so with .php
extension).
Is that possible in some way?
The . html extension can be easily removed by editing the . htaccess file.
htaccess file is created in order to enable extra features for that subdirectory. You can use the . htaccess file to modify various configurations and thus make changes to your website. These changes include authorization, error handling, redirects for specific URLs, user permissions, etc.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With