If i set DirectorySlash Off in my .htaccess file and call the directory without the trailing slash i get an 403-Forbidden from my server. If i call it with slash everything works fine.
Could anyone explain why? Here are my fully anonymized .htaccess:
# GLOBAL CONFIG
Options +FollowSymlinks
DirectorySlash Off
AddDefaultCharset utf-8
php_value post_max_size 256M
php_value upload_max_filesize 256M
# BEGIN WordPress
RewriteEngine On
RewriteBase /folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder/index.php [L]
# END WordPress
# REMOVE WWW
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
As you know per the documentation, when
DirectorySlashis set toOff, requests to/folderdo not haveDirectoryIndexevaluated. This means that the request will not be automatically mapped to/folder/index.php.mod_dirperforms this check in the “fixup” phase of the request processing.mod_rewrite, which is responsible for yourRewriteRuledefinitions, also performs its processing in this phase when you specify the rules in a.htaccessfile.However, it was programmed with an awareness of modules like
mod_dir, and includes a check to make sure that the current directory was requested with a trailing slash. If not, it declines to handle the request, since doing so might lead to undefined behaviour.The request then moves on to the content-generation phase, which, since the request was not mapped to a real file, is handled by
mod_autoindex. Given thatIndexesare disabled on your host by default,mod_autoindexreturns403 Forbiddenwhich is what you see.Note that since
DirectoryIndexis not evaluated, even ifmod_rewritewere to process the request, it would still fail, because no auto-resolution toindex.phpwould occur, and your rulewouldn’t match, because the
.requires a match on something (but the request would be blank).Enabling
DirectorySlashprevents this scenario by correcting the prevented actions in all of the previously mentioned scenarios except the last note, which is taken care of by the fact thatDirectoryIndexmaps the request toindex.phpanyway.