/ WhatILearned

Blocking Referral Spam using htaccess

As part of a photobooth project (photomatico) I've been digging deeper into Google Analytics.

One of the things that crept up during a recent bandwidth analysis was a significant difference between the referrals and the number of hits. Referrals is information into the source of the traffic, they should be proportional to each other.

I noticed that I started getting a lot of referral traffic from sites like floating-share-buttons.com. Which was confusing because while I do have sharing buttons, I wrote my own code and didn't rely on any other services. This is when I learned about referral spam, whose focus seems to be to clog up your analytics traffic and to tempt the website owner (or whoever is looking at the analytics) to research more into the services (and perhaps buy?).

It was annoying enough that I decided to modify my .htaccess file in the root www/ folder to have the following rules. If you already have the you simply add it in. Here's what I've added.

<IfModule mod_rewrite.c>
##
## Other rewrite rules here....
##
## SITE REFERRER BANNING
RewriteCond %{HTTP_REFERER} floating-share-buttons.com [NC,OR]
RewriteCond %{HTTP_REFERER} 4webmasters.org [NC,OR]
RewriteCond %{HTTP_REFERER} trafficmonetizer.org [NC,OR]
RewriteCond %{HTTP_REFERER} erot.co [NC,OR]
RewriteCond %{HTTP_REFERER} yourserverisdown.com [NC,OR]
RewriteCond %{HTTP_REFERER} event-tracking.com [NC,OR]
RewriteCond %{HTTP_REFERER} traffic2money.com [NC,OR]
RewriteCond %{HTTP_REFERER} buttons-for-website.com [NC,OR]
RewriteCond %{HTTP_REFERER} success-seo.com [NC,OR]
RewriteCond %{HTTP_REFERER} free-social-buttons.com [NC,OR]
RewriteCond %{HTTP_REFERER} Get-Free-Traffic-Now.com [NC,OR]
RewriteCond %{HTTP_REFERER} e-buyeasy.com [NC,OR]
RewriteCond %{HTTP_REFERER} videos-for-your-business.com [NC,OR]
RewriteCond %{HTTP_REFERER} callgirlservices.in [NC]
RewriteRule ^(.*)$ – [F,L]
##
</IfModule>

The effect of these changes is that any traffic from these domains will automatically be denied. This means no loading or hit on your analytics. It also mmeans you should be careful to not accidentally deny any real traffic from "real" referrers.

After a few days of testing I noticed that the referral spam has completely wiped out! Easy Success!