Shared hosting, everything working as desired for years.
But... when...
I moved from Apache 1.3 to Apache 2, my zero-byte Custom 403 is no longer working as desired.
My Root .htaccess file uses mod_access to deny a list of bot IPs.
Below that I have some mod-rewrite UA banning Rules.
I scoured WebmasterWorld and tried several of jdM's suggestions, but I'm still struggling after 3 days trying.
My banning Rules all work, but in my logs it's plain from the byte-size that banned visitors are seeing the default 403: ie. Instead of 403 0 my logs show 403 298 or 403 529 etc.
Here's the relevant bits of my Root .htaccess
ErrorDocument 404 /noexist.htm
ErrorDocument 403 /403.htm
<Files *>
order deny,allow
# Nasty cidr 1
deny from nn.nnn.n.n/11
# Nasty cidr 1
deny from nn.nnn.n.n/16
# ALLOW these exceptions
allow from nn.nnn.nn.
</Files>
# FILTER REQUEST METHODS
RewriteCond %{REQUEST_METHOD} ^(OPTIONS|TRACE|DELETE|TRACK) [NC]
RewriteRule ^(.*)$ - [F,L]
# BLOCK REQUESTED URLs and QUERY STRING EXPLOITS
RewriteCond %{REQUEST_URI} \.php|\.rdf|\.asp|\.dll|register|crossdomain|\_vti\_|https?|\(null\)|proc/self/environ [NC,OR]
RewriteCond %{QUERY_STRING} (environ|iframe|localhost|mosconfig|scanner) [NC,OR]
RewriteCond %{QUERY_STRING} (menu|mod|path|tag)\=\.?/? [NC,OR]
RewriteCond %{QUERY_STRING} boot\.ini [NC,OR]
RewriteCond %{QUERY_STRING} echo.*kae [NC,OR]
RewriteCond %{QUERY_STRING} etc/passwd [NC,OR]
RewriteCond %{QUERY_STRING} \=\\%27$ [NC,OR]
RewriteCond %{QUERY_STRING} \=\\\'$ [NC,OR]
RewriteCond %{QUERY_STRING} \.\./ [NC,OR]
RewriteCond %{QUERY_STRING} \? [NC,OR]
RewriteCond %{QUERY_STRING} \: [NC,OR]
RewriteCond %{QUERY_STRING} \[ [NC,OR]
RewriteCond %{QUERY_STRING} \] [NC]
RewriteRule ^(.*)$ - [F,L]
## I added this to stop the new server looping
RewriteCond %{REQUEST_URI} !^/403.htm$
##
RewriteCond %{SERVER_PROTOCOL} ^HTTP/1\.0$ [NC,OR]
RewriteCond %{HTTP_REFERER} sites\.google|spruz|wareseeker|warez [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^$ [NC,OR]
RewriteCond %{HTTP:X-Moz} ^prefetch$ [OR]
RewriteCond %{HTTP:X-Purpose} ^instant$
## What worked on Apache 1.3
#RewriteRule .* - [F,L]
##
RewriteRule !403\.htm$ - [F]
That final Rule was jdM answer to a similar question, but it isn't working for me. My code is banning a visitor, but not allowing them to see the Custom zero-byte 403.htm file, so they get the default 403 instead.
Should I move the 403.htm to a dir outside of Root?