What is Hotlinking
Hotlinking is the process of displaying an image on a website by linking to the same image on another website. It is mostly occurs with images. In simple words suppose i want to show some gadget picture on my website so instead of uploading the picture on my website, i link this picture to someone website using source as http://someone.com/gadget1.jpg.
Why Someone Hotlink Your Website Images
To save their server cost/bandwidth. The other reason might be they are very lazy to upload the image on their own server. If you don’t prevent hotlink then definitely it increases load on your web server. To prevent hotlinking you need to define htaccess directives.
How to Prevent Hotlinking Through .htaccess
If you don’t know about .htaccess. Read my previous post on htaccess tutorial , Deny access of files and folders through .htaccess and How to leverage browser caching.
1. It prevents all the domain from hotlinking except webrewrite.com
1 2 3 |
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?webrewrite.com(/)?.*$ [NC] |
2. Prevent abc.com from hotlinking
1 2 |
RewriteEngine On RewriteCond %{HTTP_REFERER} ^http://(.+\.)?abc\.com/ [NC,OR] |
3. Display images steal warning. In this case if someone try to hotlink it shows the warning image.
1 2 3 4 |
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?webrewrite.com(/)?.*$ [NC] RewriteRule .(gif|jpe?g|png|bmp)$ /stop_steal.jpg [L,NC] |
These htaccess directives solve hotlinking problem.