How to block referrer traffic using .htaccess

The short version

Block from your site by adding these lines to your .htaccess file

# block visitors referred from
RewriteEngine on
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]

The long version

This is going to a massively geeky post compared to my usual rubbish but I hope at least a few people will find it useful.

A few days ago, I was checking the site stats on and noticed that a domain – – kept popping up with a url that contained ‘competitors_review.php’. I took a look at the link (I’m deliberately not posting that up the link since I think that’s what these traffic spammers want) and there’s very little information: just a sign-up form. I did a bit of digging around and judging by what I’ve seen on other blogs and on Twitter, the general consensus is that are best avoided and there’s a whole load of suspicion about why they’re trying to harvest information about people by getting them to sign up to whatever service it is they’re offering with their Facebook accounts. It’s kind of clever – playing on people’s curiosity and making it look like a ‘competitor’ site is gleaning information from your site – but it stinks. If anyone from wants to put the counter argument, I’m all ears.

Update 21 Jan 2014: found a couple of other blogs with a bit more info about See WTF is and What is the website about?

Anyway, onto the practical bit. I’ve now blocked from appearing in my site stats by adding these lines of code at the end of my .htaccess file. Disclaimers: the .htaccess directives below are based on information in Media Temple’s knowledge base article: How to block a specific IP address from accessing your website. This works for my particular WordPress blog and its .htaccess file. I put them at the very end of my own particular .htaccess file. YMMV, and I provide no warranty as to what this might do to your own site. If you don’t know what your .htaccess file is or how to change it, I’d suggest you find some other way to block

# block visitors referred from
RewriteEngine on
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]

164 comments on “How to block referrer traffic using .htaccess”

  1. DerrickE says:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^http://.*semalt\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} ^http://.*kambasoft\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} ^http://.*savetubevideo\.com [NC]
    RewriteRule (.*) [R=301,L]

    This is what Alvi and Gina were trying to do, with some improvements.
    This blocks the semalt urls (including subdomains)
    and redirects their bots back to them. If you simply want to deny access, change 301 with 403

    Just place this at the very top of your .htaccess file.
    If you want to block/redirect any other domains, just add them in the following format:
    RewriteCond %{HTTP_REFERER} ^http://.*domain\.com [NC,OR]

  2. […] I haven’t tried this one yet and I typically don’t get deep into code (over my head mostly) for my clients but you can give the advanced method to block a try too.  It has to do with adding a snipit of code to your .htaccess file and I have attached some links for that too; Block Semalt or Block Referrer Traffic. […]

  3. Greg Kristan says:

    I just added this line of code to my HT Access file. I am really excited to see if this stops the amount of useless traffic and spam I keep getting to my site

    Thanks for the help!


Leave a comment