Ever had tons of traffic referred by a particular domain you wished to block? If your site is hosted on a server running Apache, it's easy to do with .htaccess. If you're not sure if the server your site is hosted on runs Apache, check with your web host.
In these situations, your hosting company may suspend your account; but by using the following .htaccess trick, you can greatly decrease the load on the server while still making your site available to others.
What's a .htaccess file?
.htaccess is essentially a plain text configuration file that provides per directory or domain instructions to Apache on how to handle certain requests relating to security and the way URLs are presented. If you can't see a .htaccess file in your file base, you can create one in NotePad or another plain text editor. Note the naming of the file ".htaccess" - the "." is important and there should be nothing after the "htaccess".
Referrer domain traffic blocking code
Here's all you need to add to your .htaccess file:
The backslash before the domain tail extension is very important to include, e.g. "lkjdfjlkd\.com"
NC, OR and F - what do they mean?
The NC flag makes the directive case insensitive so it will work on referrer traffic from the domain refererdomain.com, REFERERDOMAIN.COM, RefererDomain.com etc.
Referer vs. Referrer
Did you notice this in the code? "Referer" isn't a word in the English language, but if you spell it "referrer" in the code, it won't work. As to why this spelling was used when the HTTP protocol was developed, I really have no idea - if you know, please enlighten me so that I can add it to my party/dinner conversation repertoire :).
Will it block image hotlinking?
This htaccess hack also won't prevent other sites from hotlinking to your images; i.e. another site owner displaying your images in their content, but referencing the image directly from your server. It's a common problem that has the capacity to create excessive load and bandwidth usage on your hosting account. For a solution to this issue, see my tutorial on preventing image hotlinking with .htaccess.
The above htaccess hack isn't foolproof. If the number of requests is really over the top, it can still cause server problems as the actually request is still being made and the .htaccess file accessed. People may also still go to the trouble of typing in your domain name. The idea behind this is to alleviate a short term traffic deluge for long enough to allow your site to stay up until the storm blows over.
In the interests of transparency and disclosure, please note that the owner of Taming the Beast.net often receives goods and services mentioned in reviews for free, or may receive payments or affiliate commissions for advertising or referring others to merchants of products and services reviewed.
Copyright information.... This article is free for reproduction but must be reproduced in its entirety, including live links & this copyright statement must be included. Visit http://www.tamingthebeast.net for free Internet marketing and web development articles, tutorials and tools! Subscribe to our popular ecommerce/web design ezine!
paid cash taking online surveys - free to join online
In Loving Memory - Mignon Ann Bloch
copyright (c) 1999-2011 Taming the Beast Adelaide - South Australia