Main Tutorials

How to prevent others steal your web image (hotlinking)

My website’s images are kept directly link (hotlinking) by other websites, it’s a thief behavior and eating my bandwidth, why don’t they copy to their own server and display it? I decided to take action to stop this happened again, this so called “hotlinking” can be stopped by “.htaccess” access control.

Case Study

1. Hotlinking my image

This website directly links to my website image

steal-nohotlink

2. Design custom image

Create a custom image with paint, save it as “nohotlink.jpe“. This image file will use as your linked image replacement. Just put some text like “do not steal my bandwidth”, and upload to your server image folder.

This is my custom image

nohotlink

3. “.htaccess”

Place a file called .htaccess in your hosting’s Apache root directory. e.g /public_html/.htcaccess

Put this text into your .htaccess file.


# BEGIN prevent hotlinking image
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?yourwebsitehere\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /image/nohotlink.jpe [L]
</IfModule>
# END prevent hotlinking image

Replace the text “yourwebsitehere” with your website name. More explanation here

4. Test

The image is replaced with your custom image ~

steal-nohotlink-1

Alternative solution

The alternative solution is watermark your image, but it still eats up your bandwidth.

Conclusion

I just do not like this kind of direct image link behavior, please do not steal like this, why not just print screen and put the image on your server? It’s quite easy also 🙂 ~

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
omarete
9 years ago

Probably that poor guy never knew he was eating your bandwidth 😛

Vinod Kumar Kashyap
9 years ago

Great Tip!!! Thumbs Up 🙂

Rados?aw Osi?ski
9 years ago

Wow! Thank you for this tip.