I'd like to express this ruleset
If the request is /hello
then try the following in the given order:
/hello
— File of that name exists (file without file extension).- Edit: Not a necessity. Only a possibility/compromise. Drop if too complicated.
/hello.html
- File of that name plus .html extension exists./hello/index.(htm|html|php)
— Folder of that name with index file exists. Note: /hello/ directory listing shall explicitly be forbidden/index.php
— If nothing of the above matched hand over to CMS index.php (e.g. Wordpress)
My .htaccess in the domain root folder of my shared hosting account:
## Request without file extension
# e.g. "/hello"
### First look for DirectoryIndex files (with mod_dir)
# e.g. "/hello" shall serve "/hello/index.(html|htm|php)" if present
# Explicitly forbidding directory listings (for security/privacy)
<IfModule mod_dir.c>
Options -Indexes
DirectoryIndex index.html index.htm index.php
</IfModule>
### If no DirectoryIndex found then try with .html suffix (with mod_rewrite)
# e.g. "/hello" shall serve "/hello.html" if present
<IfModule mod_rewrite.c>
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
## Everything else goes to Wordpress index.php and its standard htaccess configuration like this:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Problems
mod_dir
'sDirectoryIndex
alone works:
- ✅ Requesting
/a01
serves/a01
being a file without suffix. - ✅ Requesting
/a02
serves/a02/index.html
which is the DirectoryIndex.
mod_rewrite
'sRewriteRule
which tries with an added.html suffix
alone works:
- ✅ Requesting
/a03
serves/a03.html
. - ❌ But now requesting
/a02
returnsApache error page 403 Access forbidden
. - ❌ And now requesting
/a01
returnsWordpress error page 404 Not found
.- Strange because that file exists and hence in the htaccess Wordpress section
RewriteCond %{REQUEST_FILENAME} !-f
is not even met, so how can that even land in Wordpress routing.
- Strange because that file exists and hence in the htaccess Wordpress section
- So
mod_dir
andmod_rewrite
rules being active together seemingly result in a conflict.
- Is a central ruleset of my webhost interfering with this?
- Or is this a general interplay issue of the two modules? How do I get them to work together as intended?