What's Image Hotlinking and How to prevent it ?
It's someone that's directly taking the URL from your server and embedding it on their website. It's kind of image stealing, but most importantly the owner gets to pay for the bandwidth. When someone hotlinks an image in their website it will look like it's being served from their server. In fact, it's being served from your server. Every time the image loads on their website, it costs the owner the bandwidth. So in order to prevent it, it's usually recommended to use .htaccess in the apache server.
Step 1: Create .htaccess
If there's no htaccess file we may have to create one for this. We can do this easily by opening a notepad and saving the file as .htaccess. Those who have the file they can just open it.
Step 2: Code to Block hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain2.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/a0YYDvt.jpg [NC,R,L]
So what does this code actually do on our website?
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain2.com [NC]
This is the list of sites allowed for the hotlinking images, so by default, all sites are blocked for hotlinking the images except those listed in the code.
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/a0YYDvt.jpg [NC,R,L]
In between the round brackets ( ) are images we intend to block from hotlinking. To add more formats we just separate them with " | "
We can change the http://i.imgur.com/a0YYDvt.jpg to our own image. So whenever someone is hotlinking images from our site this image will show up. We just have to be sure that this image is not in our server as our server is hotlink protected.
Comments
Post a Comment