Prevent HotLinking with .htaccess

HotLinking is stealing people’s bandwidth by linking directly to other site’s images, js, css files etc. If you are a site owner and want to prevent hotlinking or serve an alternate content, here is an easy solution using .htaccess.

It is fine for people to take images, css, js and other medias from your site as long as they re-host it on their own server after making a copy. Also, known as HotLinking, stealing people’s bandwidth by linking directly to other site’s images, js, css files is a bad thing. If you are a site owner and want to prevent hotlinking or serve an alternate content, here is an easy solution using .htaccess.

Create a .htaccess file and place it on the root of the domain where you want to prevent hotlinking. In my case, it was http://www.brajeshwar.com/. Add or append, the following codes between the Rewrite Rule else create the same.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?brajeshwar.com/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]
</IfModule>

This will prevent hotlinking to my gif, jpg, js and css files.
Note: mod_rewrite should be enabled for this to work.

In an event where you want to replace a hotlinked media with an alternate media, here is the change for the .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?brajeshwar.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://media.brajeshwar.com/i/brajeshwar.jpg [R,L]
</IfModule>

So, they will see me instead of the hot linked image. ;-) This came to light after Jason Scott’s article on Freedom, Justice and a Disturbingly Gaping Ass (via : Digg).

Google Defines Hotlinking as the intentional usage of someone’s bandwidth without that person’s authorization. It is also known as Bandwidth Theft.

ELSEWHERE


Don't like it? There are lots of published articles, pick a random one.

oCricket

Brajeshwar posted this article on Fri, Jan 26th, 2007 at 12:11 am
Categorized under Technology and has the following tags

Prev Article: Watch your steps before you upgrade to Wordpress 2.1

Next Article: How to track your Flickr Photos Statistics

Archives: Visit the Archives for more articles.

Comments Post Yours

There are 2 responses so far. You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.

  1. Great post!
    stealing your web content(css, images, etc.) is bad enough, but they actually have the nerve to steal it using your bandwidth? Yikes!

    I am new at this, but I never thought that this was an issue.

  2. mod_perl’s PerlTransHandler provides a much nicer way to do url rewriting without the security problems that have plagued mod_rewrite.

Post yours

Sidenotes

Quick notes, scribbles, somehow related to this website and to what I do. Or perhaps I'm just plain lazy to make them into a full article.

Great Indian Developer Summit 2009

I got a Press Release of the upcoming GIDS '09 and here is an excerpt. The summit's program covers Java, REST, Unit testing, Groovy, Spring, Struts 2.0, SOA, Cloud Computing, Web Services, JRuby, RoR, Ruby, JVM, ...21st Jan, 2009

The flourishing gun market in Pakistan

VICE Travel: Darra, Pakistanby Top-Notch112 (Via: Deep Green Crystals) 20th Jan, 2009

Angry Ringtone for iPhone and others

[audio:http://audio.brajeshwar.com/angry-ring-ring.mp3] The ANGRY RINGTONE for iPhone. (Click the PLAY button above!) Download * iPhone Ringtone (.m4r) * MP3 Ringtone (.mp3) * Zipped (both .m4r and .mp3) To use it as an iPhone Ringtone; just double click the file "angry-ring-ring.m4r" and it ...15th Jan, 2009

IIM Ahmedabad's Leverage 2009

Leverage, the Venture Capital and Private Equity Club of IIM Ahmedabad and the Centre for Innovation Incubation and Entrepreneurship bring to you the 1st edition of the Venture Capital and Private Equity Conference on the ...12th Jan, 2009

Fedora 10 Released

Let's talk history! Fedora was created in late 2003 as a Linux based Operating System which gives the users an admittance from anywhere in the world to the most up-to-date free and open source software ...28th Nov, 2008

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • Not Safe for Work Ever clicked a link and felt embarrassed with the content in front of your co-workers? Ever caught unaware because the funny link your friend sent was a little beyond funny? Let’s minimize that with NSWF.
  • Forum Oinam’s technical discussion forum where developers and designers can discuss all technical topics.
  • Ode to Apple Dedicated to Apple - Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • oCricket oCricket is about Cricket and people enthusiastic about it.
  • My Special Job My Special Job is a place where you can look for your weird necessities, strangely superb employees, when your need are more of those hackers, geeks, and ultimate rockstars in the Internet Technology.
  • ActionScript 3.0 Reference Flash/Flex ActionScript 3.0 Reference.
  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.

Download free Brajeshwar Wordpress Theme

Brajeshwar

Brajeshwar I firmly believe in keeping things simple, easy for users and I envison pushing the technical envelop time and again for the betterment of viable commercial and practical applications. More about me.

Brajeshwar's affinity with Adobe

My Photos

More photos on Flickr

Member of 9rules Network

Since its inception on 11th June, 2001, "Brajeshwar" has 949 Articles and 6,472 comments, contained within 22 categories and 1,497 tags.