Blocking users or sites that originate from a particular domain is a very useful trick of .htaccess. Lets say you check your logs one day, and see tons of referrals from a particular site, yet upon inspection you can’t find a single visible link to your site on theirs. The referral isn’t a “legitimate” one, with the site most likely hot linking to certain files on your site such as images, .css files,  or files you can’t even make out. Especially those mp3 audio or mp4 video files. They are large files. The site hot link your content will eat a lot of portion of your bandwidth, CPU time. The result is make the normal user of your site loading page slower than normal.

Remember, your logs will generate a referrer entry for any kind of reference to your site that has a traceable origin.

Here I have some example of how to write the .htaccess file for Apache Web Server.

RewriteEngine On
RewriteCond %{HTTP_REFERER} .*mp3stahuj.cz.*$ [OR]
RewriteCond %{HTTP_REFERER} .*gdd.ro.*$ [OR]
RewriteCond %{HTTP_REFERER} .*profil.lide.cz.*$ [OR]
RewriteCond %{HTTP_REFERER} .*yahoo.com.*$
RewriteRule ^(.*)$ -

Blocked referrers will be shown a ‘403 Forbidden’ error message.

David Yin

David is a blogger, geek, and web developer — founder of FreeInOutBoard.com. If you like his post, you can say thank you here

Leave a Reply

Your email address will not be published. Required fields are marked *