Blocking Referrer Spam

I knew there was something wrong. Suddenly, there were tens of visitors coming to Adventures in Play each day! I just knew I wasn’t that popular. Using Google Analytics,  I dug a little deeper to learn more about my sudden jump in popularity.

 

Google_Traffic

If you do not have Google Analytics set up on your WordPress site, I highly recommend investing the time to install it. It’s a statisticians dream, but more than that, it is a great way to drill down into your blog posts to learn where traffic is coming from and which posts are most popular.

There are a multitude of guides on how to get started. I found this particular article to be good. It offers a step-by-step guide for WordPress users:

Link:
http://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/

So, I see lots of traffic but is that a bad thing?

Referrer spam is a bad thing because it represents false traffic and it messes with your Google Analytics. I’m interested in the 5 real visitors, not the hundred or so mindless bot hits.

Besides, there is an easy fix to keep these sites out. All you need to do is modify your .htaccess in the root of your WordPress website. There are several ways to go about this, but I found using the cPanel dashboard to be one of the most direct.

How to Block Span Referrers

Go to your cPanel management website and locate the Files section. This is not possible if your WordPress is hosted at WordPress.com. The steps below only apply to WordPress.org websites.

Within Files click on File ManagerCPanel_FileManager

File Manager Directory Selection window will appear.
From the Document Root for: choose your website from the dropdown box, then click GoCPanel_SiteSelect

Before we modify the .htaccess file, let’s make a backup. That way, if you mess it up, your website won’t be hosed.

From the File Manager, click on Copy.
cPanel_Copy

Next, a Copy window will appear.
Enter the destination of the backup file. I choose the name “bak.htaccess“.
Click Copy File(s) button to save a backup.cPanel_Backup

Now you are ready to edit the .htaccess file directly.
Select .htaccess and then click Code EditorCPanel_FileEdit

Code Editor window may appear prompting for the character encoding type.
For now, click edit (UTF-8 is fine for me).CPanel_CodeEdit

Now for the fun part. Insert the site referrer banning rules just before the WordPress <IfModule mod_rewrite.c> section:

Example commands to filter our referrer websites:

RewriteEngine on 
Options +FollowSymlinks

RewriteCond %{HTTP_REFERER}  ^([^.]+.)*?trafficmonetize\.org [NC,OR]
 # Add other RewriteCond rules here
 
RewriteRule .* - [F]

What is the [NC,OR] doing at the end of the statement?

  • [NC] Tells WordPress to do a case insensitive comparison
  • [OR] Is a logical OR operation

*Tip: Do not add [OR] to the last RewriteCond in your filter list.

My .htaccess file looks like this:


AddHandler application/x-httpd-php52 .php .php5 .php4 .php3
## SITE REFERRER BANNING
 # Block traffic from multiple referrers
 RewriteEngine on
 Options +FollowSymlinks
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?trafficmonetize\.org [NC,OR]
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?4webmasters\.org [NC,OR]
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?webmonetizer\.net [NC,OR]
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?floating-share-buttons\.com [NC,OR]
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?www.event-tracking\.com [NC,OR]
 RewriteCond %{HTTP_REFERER} ^([^.]+.)*?free-social-buttons\.com [NC]
 RewriteRule .* - [F]
 # BEGIN WordPress
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
 # END WordPress

Warning: Be careful when editing the .htaccess file. If you don’t edit the file correctly, your website might not load or will inadvertently filter out otherwise welcome visitors.

Click Save and you should be all set. Be sure to test if your homepage loads properly. If you did something wrong you can always restore the backup and try again.

Zero_VisitorsNow that’s more like the blog I know!

 

2 thoughts on “Blocking Referrer Spam

Leave a Reply