Forum Moderators: phranque
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
RewriteEngine on
# www
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
# allow all except those indicated here
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 78.158.11.226
deny from 123.125.71.109
deny from 220.181.108.151
deny from 220.181.108.151
deny from 213.186.122.3
deny from 193.106.136.62
deny from 114.79.3.182
deny from 93.182.136.176
deny from 208.115.113.*
deny from 222.38.98.*
deny from 113.157.220.*
deny from .*alexiadns\.com
deny from .*evuln\.com.*
deny from .*ahrefs\.com.*
</Limit>
# deny access to evil robots site rippers offline browsers and other nasty stuff
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
Belt and suspenders? You're securing htaccess twice. There's an alternative command for blocking all files with leading dot. Was going to go look up the precise wording, but Apache just scared me out of my wits by being unavailable :) and this is not a time for "If I remember correctly..." (Can't quote my own htaccess because the host has this bit in the config file.)
Why limit them? These are people you want to lock out unconditionally, right? Commands other than GET should be constrained as tightly as possible.
ymmv, but long strings of OR-delimited RewriteConds might work better using SetEnvIf. Flag each one separately as "bad_bot" or "keep_out" or other name to taste, and let your Deny from directive include a single "Deny from env=keep_out" line.
Don't do redirects with RewriteRule before blocking access with RewriteRule. Why redirect something you then block?
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc] # deny access to evil robots site rippers offline browsers and other nasty stuff
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
Belt and suspenders? You're securing htaccess twice. There's an alternative command for blocking all files with leading dot. Was going to go look up the precise wording, but Apache just scared me out of my wits by being unavailable :) and this is not a time for "If I remember correctly..." (Can't quote my own htaccess because the host has this bit in the config file.)
Please do tell when it'll be available.
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch> And about belt, and suspenders, does it create a conflict, or is just overkill, and harmless?
Why limit them? These are people you want to lock out unconditionally, right? Commands other than GET should be constrained as tightly as possible.
And how would that be done? I remind you I did a patchwork, I am a complete illiterate ... well I do know how to read, and write ;)
<FilesMatch "(forbidden|goaway|missing|cell)\.html">
Order Allow,Deny
Allow from all
</FilesMatch>
<Files "errorstyles.css">
Order Allow,Deny
Allow from all
</Files>
<Files "robots.txt">
Order Allow,Deny
Allow from all
</Files> ymmv, but long strings of OR-delimited RewriteConds might work better using SetEnvIf. Flag each one separately as "bad_bot" or "keep_out" or other name to taste, and let your Deny from directive include a single "Deny from env=keep_out" line.
Can you please cut it down more, I understand your suggestion to use SetEnvIf, but didn't get how to do it correctly.
Also would that be applied to a long Deny list?
BrowserMatch ^-?$ keep_out
BrowserMatch "America Online Browser" keep_out
BrowserMatch Clipish keep_out
BrowserMatch Covario keep_out
{snip}
BrowserMatch Wget keep_out
BrowserMatch Wikimpress keep_out
BrowserMatch Yahoo keep_out
Order Allow,Deny
Allow from all
# specific addresses or conditions
Deny from env=keep_out
Deny from 23.19
Deny from 31.214.128.0/17
Deny from 37.59
{et cetera} - block with deny/allow
- block with RewriteRule
I have to read the posts few times, as I'm almost more confused ... not for the posts, which are obviously competent, but due to my lack of knowlege.