Reputation: 731
I currently have this as my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])$ $1.php
RewriteRule ^(.*)/$ $1.php
The above rewrites domain.com/page/
or domain.com/page
to domain.com/page.php
It works really well but for file management on server it would be more convenient to be access the /folder/index.php
files from /folder/
or /folder
URL instead of looking for /folder.php
Is that possible?
Upvotes: 1
Views: 63
Reputation: 785246
You can use these 2 rules:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
Upvotes: 2