I am trying to use .htaccess to rewrite requests for PHP files that don't explicitly include the .php file extension (e.g. example.com/foo should rewrite to example.com/foo.php), but without applying that rule to any folders (or subfolders) of the document root.
My http.conf file contains following:
DocumentRoot "/webfiles"
<Directory "/webfiles">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Alias "/exams" "/training/exams"
<Directory "/training/exams">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
DirectoryIndex index.php
There is a .htaccess file in the /training/exams folder containing following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
The goal is to:
- serve requests like
example.com/examswith/training/exams/index.phpfile, - serve requests like
example.com/exams/firstwith/training/exams/first.phpfile, - while still having requests like
example.com/myhome.htmlserved with/webfiles/myhome.html.
Examples 1. and 3. work fine, but for 2. I get a 404 error.