Advanced .htaccess Security – Block Unwanted Referrers

By  on  

For some bloggers and web developers, Digg can be a huge boost in traffic and thus a huge bust in ad revenue. Unfortunately, the Digg Effect can kill a website's bandwidth and get the website shut down. Wouldn't it be great if a weary web developer could prevent his site from being shut down by blocking users referred by Digg, at least a while? Using a small bit of .htaccess code and mod_rewrite, the developer can do just that.

The Code

RewriteEngine on
RewriteCond %{HTTP_REFERER} digg.com [NC]
RewriteRule .* - [F]

Say good-bye to Digg Death with this small, easy-to-place snippet of code!

Recent Features

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

Incredible Demos

  • By
    Flashy FAQs Using MooTools Sliders

    I often qualify a great website by one that pay attention to detail and makes all of the "little things" seem as though much time was spent on them. Let's face it -- FAQs are as boring as they come. That is, until you...

  • By
    Record Text Selections Using MooTools or jQuery AJAX

    One technique I'm seeing more and more these days (CNNSI.com, for example) is AJAX recording of selected text. It makes sense -- if you detect users selecting the terms over and over again, you can probably assume your visitors are searching that term on Google...

Discussion

  1. David,

    I have a quick question for ya… can you make this .htaccess so you can transfer them to a “slimmed” down version of the same page or simply a blank page that says sorry digg users the site is offline for awhile?

    One more question. When digg or any other site goes down for scheduled maintenance do they use this method to redirect all pages to a sorry we are down page?

    Mark

  2. Not a bad idea with your first question, Mark. Per your idea, I’d create a new sort of page template to do this. Say that “page.php” is getting hit hard and you want to show a slimmed down page. On page.php, you could check the referrer and if the referrer was digg, you could do a header() redirect to “slimpage.php?page=”.(yourpage). You’d them have slimpage.php provide a text-only version of your article.

    As for a site being down, I’d bet that this is what they do. It’s very easy and very simple. Unfortunately, Digg, for example, doesn’t allow you to view their .htaccess file anymore.

  3. What do you think abut blocking : “Options FollowSymLinks”, i think this is important also

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!