Quantcast

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.

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

Suggest 1 or more tags for this article

Use a comma (,) to separate 2 or more tags.

[?]

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

Next Article: How to track your Flickr Photos Statistics


Possibly Related Articles

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.

Download Free book: The Photoshop Anthology

Sitepoint is giving away an entire 278 page Photoshop book for free (pdf). It will only be up for grabs for 30 days. The entire 278 page book, yours to keep, forever! The Photoshop Anthology: ...15th May, 2008

FreshAIRApps

James Whittaker's FreshAIRApps is not just a website that showcase some of the best and popular Adobe AIR Applications but also provides the community with AIR updates, tutorials and other resources. The Showcase is the main ...13th May, 2008

Adobe Feeds Aggregator

MXNA's been a good resource site for Adobe Technology with articles being aggregated from many blogs. However, of late, there were lots of uproar from the community as MXNA wasn't able to withstand the traffic ...6th May, 2008

Iron Man, the Movie

Images of Iron ManIron ManTony Stark is forced to build an armored suit after a life-threatening incident, he ultimately decides to use its technology to fight against evil. Tony Stark (Robert Downey Jr) is a billionaire ...1st May, 2008

Adobe AIR for JavaScript Developers

Reading Mike Chambers latest post let me to Ajaxian's article on the release of the free eBook -- Adobe AIR for JavaScript Developers Pocketguide. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License, the book provides an ...18th Apr, 2008

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • Oinam The official conglomerate of the Oinam related companies, institutes and holdings.
  • Downloads All downloads, Free and Open Source.
  • AS 2.0 Reference Reference for ActionScript 2.0 Programming Language used in Flash. Primarily stashed here for my own personal reference.
  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.
  • ActionScript 3.0 Reference Flash/Flex ActionScript 3.0 Reference.
  • Ode to Apple Dedicated to Apple - Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • Forum Oinam’s technical discussion forum where developers and designers can discuss all technical topics.

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.

Want to know more about me?

Brajeshwar's affinity with Adobe

My Photos

More photos on Flickr

"Brajeshwar" has 790 Articles and 5,587 comments, contained within 17 categories and 970 tags.

This site is in operation since 11th June, 2001.