Multiple bad referrers to my web-site

Avatar
  • Answered
I noted your instructions about blocking bad referrers in the .htaccess file. My puzzle is that I now have 75 + bad referrers, mostly from Russian sites (plus some other "rude" ones) that can have no possible connection to my UK site. Can I use the following e.g., or do I have to note each web-site separately? Also, is the format 1. Engine On; 2. name the site; 3. .* -F for each of them separately or just 1x Engine at the beginning and 1x -F at the end of all the sites/countries??
My e.g.
RewriteEngine On
RewriteCond %{HTTP_REFERER} *\.ru [NC]
RewriteCond %{HTTP_REFERER} *\.kz [NC]
RewriteCond %{HTTP_REFERER} *\.ua [NC]
RewriteCond %{HTTP_REFERER} *\.am [NC]
RewriteRule .* - [F]

Any help appreciated
Dave B. Hove U.K.
Avatar
JacobIMH
Hello Dave, and thank you for your question. If you happened to follow my guide on block bad referers, one thing you'll notice that your current .htaccess rules are missing is the [NC,OR] clause at the end of each line except for the last one including .am. The reason you need that is otherwise Apache will try to match all of your rewrite conditions, and you'll never encounter a referer that is coming from both .ru AND .kz at the same time. So you've got to let Apache know that any of these rewrite conditions can be met by using the OR condition. You only need to turn on the RewriteEngine once, and you only need one RewriteRule. Depending on how many TLDs (Top Level Domains) you plan on blocking, you might also find the SetEnvIfNoCase method easier to maintain like this:

SetEnvIfNoCase Referer "\.ru" bad_referer SetEnvIfNoCase Referer "\.kz" bad_referer SetEnvIfNoCase Referer "\.ua" bad_referer SetEnvIfNoCase Referer "\.am" bad_referer Order Allow,Deny Allow from ALL Deny from env=bad_referer

Please let us know if you had any other questions at all. - Jacob