Reputation: 735
so I have a relatively simple site where all the pages have a .php extension, i.e about.php, gallery.php etc. I also have a services.php file and also a subfolder in the directory named services. For greater clarity my structure is below:
root
|
|-index.php
|-about.php
|-gallery.php
|-services.php
|-contact.php
|-services/
|-service-one.php
|-service-two.php
|-service-three.php
|-service-four.php
As you'll see I have a services.php and services folder. In the root I have the following htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This allows about.php, for example, to be accessed without the .php extension so http://www.domain.com/about works as about.php would. However when I try http://www.domain.com/services, I get neither the directory listing or the services.php page. I get the following message which gives a couple of clues.
The requested URL /services/.php was not found on this server.
I've been unable to find a way to resolve this, I'm wondering if I need an htaccess in the /services folder?
Thank you.
Upvotes: 1
Views: 202
Reputation: 785286
You need to tweak your regex to match everything before last /
:
DirectorySlash Off
Options -MultiViews -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
Also note modification in RewriteCond
to check for existence of .php
file.
Upvotes: 1