This is where things will get a little technical because we are going to access and edit your htaccess file via FTP.

If you are using a WA hosted site you should be able to follow along here and see results.

I also need to disclaim that I am not an expert in IT and if you have very technical questions about editing your htaccess file, I may not be able answer them as I have limited experience outside of this process.

The first thing we need to do is access the htaccess file via FTP. This file will allow us to block specific referral sites and prevent spam.

IMPORTANT:Before you edit this file, you should save a backup copy.

1. Log into your site via FTP (I use Filezilla)

2. Open your httpdocs folder on the WA server


3. Go to your htaccess file

4. Right click And choose Download (just to save a backup copy)


5. Right click the file again and choose View/Edit


This will open up you htaccess file for editing. It will open as text file.

Here you will add code that is going to tell your site how you would like it to handle referral spam.

Below I will show you how to block traffic from:

  • One URL (websitename.com)
  • A URL with a sub domain (i.e. subdomain.website.com)
  • Multiple URL’s at one time

Choose one of the options below and paste the code into your htaccess file.

It can go anywhere in the file as long as it is not in between an OPEN <if module>. You can see my htaccess file at the bottom

Block Traffic From A Standard URL

In this example i will block traffic from 1 standard URL (websitename.com).

Put the following code in your htaccess file and replace websitename.com with whatever standard URL you want to block:

# block referrer spam                                                          RewriteEngine On                                                               RewriteCond %{HTTP_REFERER} websitename\.com [NC]                              RewriteRule .* – [F,L]

The code above tells the server to block all traffic from websitename.com.

The[NC] flag tells the server that the website URL is not case sensitive. In the rewrite rule [F,L], the F tells the server to return a “403 forbidden error” and then the L tells it to stop processing.

Block Traffic From A Sub Domain URL

In this example I will block traffic from a sub domain URL (fourum5674.websitename.com)

Put the following code in your htaccess file and replace websitename.com with whatever sub domain URL you want to block:

# block referrer spam                                                          RewriteEngine On                                                               RewriteCond %{HTTP_REFERER} ^http://.*websitename\.com [NC]                    RewriteRule .* – [F,L]

The code above tells the server to block all traffic from ANY sub domain from websitename.com.

Now we can combine these codes and block multiple spam referral URL's.

Block Traffic From Multiple URL's

In this example we will block several spam referral URL's. To do this we use the OR flag.

The example below is my exact htaccess coding you can copy. You just may need to add more sites in for which ever ones are spamming you.

# block referrer spam                                                          RewriteEngine On                                                               RewriteCond %{HTTP_REFERER} buttons-for-website\.com [NC,OR]                   RewriteCond %{HTTP_REFERER} ^http://.*simple-share-buttons\.com [NC,OR]        RewriteCond %{HTTP_REFERER} simple-share-buttons\.com [NC,OR]                  RewriteCond %{HTTP_REFERER} 7makemoneyonline\.com [NC,OR]                      RewriteCond %{HTTP_REFERER} darodar\.com [NC,OR]                               RewriteCond %{HTTP_REFERER} semalt\.com/ [NC]                                  RewriteRule .* – [F,L]

If you are wondering why I have simple-share-buttons.com listed twice, it’s because I receive spam from both a standard URL and a sub domain. I am not sure if there is a better way to do that, but for me it stopped all referral spam from the site.

Also notice that the last block on Semalt.com only says [NC] after it and does not contain OR, that is because it is the last site in my list.

After you have edited your htaccess file, you need to click save and let it rewrite on the server via FTP.

Save the text file and then close it


The server will know the file has changed: Choose YES to upload

That's it! You should know see your referral spam stop for the sites you have listed.

See My Htaccess file Example

This is a picture if EXACTLY how my code sits inside of my htaccess file. Notice it is NOT in between any <if module> </if module> code.



Join the Discussion
Write something…
Recent messages
rosieM Premium
Thank you sounds too small...THANK YOU!!!! Everyone should read this.....saved and sharing!
Reply
NicheDown Premium
I appreciate your kind words. Referral spam is a big problem and it really can bring your spirits down when you see it ruining all your analytics data.

I am glad that you found the training to be of value!

-James
Reply
rosieM Premium
I really did! You laid it all out easily understood and detailed...great job!
Reply
johnwnewman Premium
Thanks, great training!
Reply
NicheDown Premium
Thanks, I appreciate your kind words!

-James
Reply
MarionBlack Premium
Thank you so much for sharing, I've been able to block 5 of those nasties from one of my websites. I would never have known where to find them in Google Analytics. ~Marion
Reply
NicheDown Premium
Hey Marion,

Glad you found the information helpful. O love that you called them "nasties"! You couldn't be more right!

-James
Reply
TheCatherine Premium Plus
I have added this to my Google Analytics training synopsis
Reply
NicheDown Premium
Thanks, That's a great resource you put together on Google Analytics. I am honored to have a link in it!
Reply
TheCatherine Premium Plus
it was only a compilation of the hard work of others but Google Analytic is so vital and so useful I wanted to make it easy for everyone to get acquainted with it
Reply
marant Premium
Wow, Just what I was looking for! Many Many Thanks!
Reply
NicheDown Premium
NP. Let me know if you need any help. I am certainly not an IT guy, but this a battle I have been fighting with referral spam for awhile.
Reply
marant Premium
It sounds like you've done quite a bit on it... how difficult is filezilla to use?
Reply
NicheDown Premium
I dont find it difficult at all. It's really pretty streamlined. I watched this training when I first set it up:
Reply
marant Premium
Thanks, Spam not too big a problem for me atm, my site still pretty new, but I want to stay ahead of it...thanks again, I know you've worked hard on it!
Reply
NicheDown Premium
Best of luck. save this as a reference. If the problem arises you can jump right on it. This took me a few weeks to learn and figure out so save your self the stress.
Reply
marant Premium
Definitley!...If you ever need some good comments...or feedbacks...or anything else..I'm your boy!!
Reply
Top