Technology Trends & Opinion » Blah, Blah! Technology blog

Where the tech' views are 667% more interesting than the tech' news itself…

My personal web pages and profiles

The Beginner's Guide to Social Media ebook button

Tag Cloud

A graphic with the words: 'Subscribe to Blah, Blah! Technology'

social networking

Twitter button FriendFeed button Facebook button

« »

Using .htaccess to block unwanted traffic

Tuesday, 3 March 2009 — by

Not all web traffic is made equal. Some websites and blogs aren’t exactly the kind of places you’d like to get a visit from. So here’s a technique for sending those visitors somewhere else…

I’ll be honest and say that the Apache web server is mostly beyond my comprehension. However, if you’re serious about web development — and if you are, you use a Unix-flavoured operating system — then you need to know some of Apache’s moves, and probably most important of all, what you can do with the .htaccess file.

Strictly speaking, .htaccess file isn’t a file. As I understand it, it’s the extension of the directory it resides within, which in part explains a little about how the .htaccess works.

First of all, to be able to follow any of the suggestions here, you need:

If you don’t, then none of the following is going to work for you.

Bouncing unwanted web traffic with RewriteCond

There are certain times when certain types of web traffic is, shall we say, undesirable. I suppose in a way, it’s a mark of the progress I’ve made with the Blah, Blah! Technology blog when I look at some of the undesirable web traffic I receive. So just how did I stop these visits to my blog?

Connect to your website via your FTP client of choice and look for an existing .htaccess file. If there isn’t one, create one and upload it onto the root of your account — the root is the base directory (or folder) that your website resides in.

If there’s already a file in place, make a backup. If the file contains any entries, be sure to ask the relevant parties what they relate to and then add your own entries to the very end of the file.

When you add a .htaccess file there, any instructions added to that file are propagated through all of the directories within the root.

It’s worth mentioning that if you’re on Mac OS X like I am, when creating your .htaccess, beware that the “.” at the beginning of the file name will most likely make the file vanish. That’s because the “.” has special significance within most Unix-based operating systems; instructing the OS to make the file invisible.

So when you create your .htaccess file, create it in the folder where it’s need on your computer; such as the folder within which you’re building your website. If not, you could have a fairly miserable time finding the file again!

Fortunately, most good FTP clients will show these files, or at least offer the option to show them. I use Transmit, by Panic for my FTP needs. I also use, their web development application, Coda, which sort of has Transmit built it.

Next, make sure you’re using a robust text editing application. Again, if you’re on a Mac, you can use either the aforementioned Coda, or BBEdit. I can’t offer any advice on PC equivalents, because I don’t use a PC. But I’m sure you’ll find suitable alternatives.

Within the .htaccess file, add the following:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://tools\.pagerush\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://www\.theseomizer\.com
RewriteRule .*[R=301,L]

I’m not going to paw over all of the code in meticulous detail. Instead, I’m going to cover the salient points to help you make this technique work.

The 2nd and 3rd lines are the entries for the websites I’m blocking traffic from. You can add as many websites as you want. When adding the web addresses, follow the formatting in those lines:

  1. place a backslash before each period character;
  2. only use the base web address, unless you want to block a specific web page;
  3. if there’s more than one entry, add the [OR] to end of each line, with the exception of the last.

The final line is the address you’re sending those visitors to. In this case, I’m sending them all to the last page on the internet, which I feel is appropriate.

It’s also worth noting that there’s a benign if not beneficial side to using the RewriteCond. You could, for example, redirect visitors from a website to specific landing page, rather than have them go into the website proper.

Above all, please use this advice diligently and responsibly…

An image with the words: 'Subscribe to Blah, Blah! Technology'

« »


Comment and be known

nokia n86 → Tuesday, 3 March 2009 @ 14:05 BDT

[The] .htaccess [file] is very powerful in modern SEO too.

Agricola → Tuesday, 3 March 2009 @ 15:13 BDT

Thanks for writing a post that we non-technical bloggers can understand and appreciate. I just got going on my own site, hosted, after years of Typepad et al. It’s daunting, but fun, to explore the possibilities and challenges that others have managed for us bloggers over the years. This is good stuff….

Revenue Robot → Tuesday, 3 March 2009 @ 15:23 BDT

Great article…! I used the .htaccess a bit back to block people from jacking my images and using them on their websites / blogs…

David Bradley → Wednesday, 4 March 2009 @ 11:29 BDT

You seem to have missed out the backslashes you mentioned…shouldn’t the code be like this

RewriteCond %{HTTP_REFERER} theblockedsite\.com

Wayne Smallman → Wednesday, 4 March 2009 @ 11:36 BDT

For some reason, WordPress saw fit to randomly strip them out. Now back in place…

David Bradley → Wednesday, 4 March 2009 @ 12:00 BDT

Yes, WP autoformating can be a pain in the neck, there is a fix so that you can embed scripts and php as well as reserved characters in a post. I *think* I described it on but if I didn’t it’s certainly in the Codex.

Mark → Saturday, 10 October 2009 @ 5:36 BDT

I’m considering using this technique to bounce StumbleUpon traffic… Sure it’s nice seeing all of those page views – but these people just stumble through… they never leave comments or anything.

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

» Subscribe to the comments feed

© Copyright Octane Interactive Limited, 1999 – 2020Search, Social Media Marketing & Optimization, Web Design & Development for Businesses | Contact | All about Blah! | Home