This month, I find that this site consumed unusual bandwidth usage. Probably, the traffic is increasing, but still, it looks a little bit strange. So, I checked my bandwidth usage log from webhosting control panel, and found an “interesting” information. I have more than 2.5 Gb of bandwidth usage only for images, only in one week. Okey, it seems that there are some sites stealing my bandwidth usage.
Few months ago, I started placing a small .htaccess inside my image directory. There are some “upload folders” inside my hosting account. Unfortunately, I forgot to put .htaccess in all upload folders. I know, I can do it easily by placing that .htaccess in the main public directory. But, because Movable Type — my current blogging platform — also generates .htaccess file inside the main public directory, I need to do another mechanism.
There are some tricks we can use to avoid hotlink prevention. For more detailed information, you can read an articles at A List Apart. It’s about Smarter Image Hotlinking Prevention. So, what’s in my .htaccess file then?
Here are some lines I put inside .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?orangescale\.net/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?orangescale\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?terasi\.net/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://orangescale.net/nohotlink.png [L]
Those lines mean:
- Avoid hotlink from other web pages but from these domains: orangescale.net, orangescale.com, and terasi.net
- If there are web pages try to do hotlinking, the referring image will be replaced by an image located at
http://orangescale.net/nohotlink.png. - Those rules will apply to all files having
.jpg, .jpeg,.bmp, and.pngextensions
There are some ‘flags’ there like [NC] and [L]. The [NC] flag makes the statement case insensitive while [L] identifies that the line is the last rule.
Why I do this? Because I do not have super-extra-bandwidth. I pay for the bandwidth. And, I tried not to do hotlink when I insert files in my posts. It is fine for me if images found in my website used by other, as long as they keep those images into their own server. After few days, it seems my bandwidth usage is back to normal.