Hotlink Images yang menguras Bandwidth

Tanpa kita sadari setiap paket web hosting yang kita beli selalu menyertakan bandwith selain paket space hosting misalnya paket Hosting 100 Mb space ( 100 mb traffic / month ) yang artinya kita berhak atas space 100 Mb dengan traffic sebesar 100 Mb per month.

Kasus traffic bandwith sering membuat akses ke website terganggu bila over qouta. Mungkin juga sering kita menjumpai web – web yang ramai pengunjung memunculkan tulisan Traffic Exceeded, nah inilah kasus over qouta yang saya maksud.

Penyebab over qouta traffic adalah :

1. Besarnya file – file dalam web kita sehingga saat orang melakukan akses ke web kita, akan terjadi traffic transfer data yang cukup besar antara web server kita dengan pc client yang melakukan akses.

2. Ramainya pengunjung web kita, semakin ramai pengunjung, sudah barang tentu semakin meningkat pula traffic transfer data yang terjadi.

3. Satu hal yang paling signifikan adalah hotlink images, adalah gambar – gambar yang tersimpan didalam web kita diakses oleh web lain. Akses yang dilakukan hanya ke gambar – gambarnya saja sehingga gambar – gambar ini bisa dimanfaatkan oleh oleh web lain. Sudah barang tentu hal ini juga mengakibatkan meningkatnya traffic transfer data yang terjadi di web server.

Antisipasi untuk yang no 3, bila web server kita ada fasilitas Cpanel nya cukup melakukan setting pada Hotlink saja, namun bila web server tidak tersedia fasilitas Hotlink, anda dapat memanfaatkan penggunaan htaccess sbb :

Example: Your site url is www.mysite.com. To stop hotlinking of your images from other sites and display a replacement image called nohotlink.jpe placed in your images directory, place this code in your .htaccess file:

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

The first line of the above code begins the rewrite. The second line matches any requests from your own mysite.com url. The [NC] code means “No Case”, meaning match the url regardless of being in upper or lower case letters. The third line means allow empty referrals. The last line matches any files ending with the extension jpeg, jpg, gif, bmp, or png. This is then replaced by the nohotlink.jpe file in your images directory. This JPEG image is using the extension jpe instead of jpg to prevent blocking your own replacement image.

To stop hotlinking from specific outside domains only, such as myspace.com, blogspot.com and livejournal.com, but allow any other web site to hotlink images:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blogspot\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?livejournal\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

You can add as many different domains as needed. Each RewriteCond line should end with the [NC,OR] code. NC means to ignore upper and lower case. OR means “Or Next”, as in, match this domain or the next line that follows. The last domain listed omits the OR code since you want to stop matching domains after the last RewriteCond line.

You can display a 403 Forbidden error code instead of an image. Replace the last line of the previous examples with this line:

RewriteRule .*\.(jpe?g|gif|bmp|png)$ – [F]

Warning: Do not use .htaccess to redirect image hotlinks to another HTML page or server that isn’t your own (such as this web page). Hotlinked images can only be replaced by other images, not with an HTML page.

As with any htaccess rewrites, you may block some legitimate traffic (such as users behind proxies or firewalls) using these techniques.

sumber : http://altlab.com/htaccess_tutorial.html