Thursday, June 20, 2013

Stopping Image Bandwidth Theft with .htaccess

A few days ago, my host notified me that my shared host account has been using more than usual CPU resources. I didn't see the email, and my site was banned. I emailed my host and asked them to un-suspend my account so I could investigate what was the problem.

I checked Google Analytics and the traffic was normal. I then checked the bandwidth usage and found that the bandwidth was very high.

I dived deeper into the problem and I discovered that some sites were hot linking pictures on my domain.

Here's the hot-linking site:



In case if you are wondering why the image is so familiar, I actually purchased it from ShutterStock.

So I have an idea - why not swap those pictures with an image to market my site?

I used Photoshop and created this.


In case you are wondering, the banner goes to appgags.com.

At the root of my .htaccess, I appended the following code:

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?appsmylife\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /images/appgags_banner.jpg [L]

Here's the result:


Unfortunately, the image is stretched due to the way that website set it.

No comments:

Post a Comment