This is my .htaccess file:
# NO LISTING OF INDEXES
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
# NIX THE www BECAUSE IT IS NO LONGER 1996 AND YOU'RE COOLER THAN THAT
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)/$ http://%1/$1 [R=301,L]
# NIX TRAILING SLASHES BECAUSE SEO IS A VENGEFUL GOD AND WHATNOT
RewriteRule ^(.*)/$ $1 [R=301,L]
# SEND ALL NON-FILE REQUESTS TO index.php FOR FIGURING OUT
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# ERROR DOCS
ErrorDocument 400 /error/400
ErrorDocument 401 /error/401
ErrorDocument 403 /error/403
ErrorDocument 404 /error/404
ErrorDocument 500 /error/500
If I try to access a folder (/images/
or /images
or some other real folder in my site structure) it falls into a redirect loop.
I tried adding RewriteCond %{REQUEST_FILENAME} !-d
before the trailing slashes rule, and that "fixed" the redirect in as far as it now enforced the trailing slash on proper folders—but also passed the folder name to my script as if it were a baked URI query for my CMS to figure out.
I guess I could now try to fix this on the CMS side by checking if the URI is a folder that someone is trying to illegally list, but ideally there would be a graceful .htaccess
solution to redirect folder listing calls to one of those forbidden pages I so helpfully declare there. Does anyone know of one?