Prevent Image Hotlinking

Published in: Linux

Put this piece of code in your .httaccess file on the Apache web server and it will automatically block all image requests coming from specified domains.

The website requesting the image resource will be returned a 403 Forbidden error.

 RewriteEngine On
 RewriteCond %{HTTP_REFERER} ^http://(www\.)?example\.ru(/.*)*$ [NC,OR]
 RewriteCond %{HTTP_REFERER} ^http://(www\.)?example\.cn(/.*)*$ [NC,OR]
 RewriteCond %{HTTP_REFERER} ^http://(www\.)?leecher\.com(/.*)*$ [NC]
 RewriteRule \.(jpeg|JPEG|jpe|JPE|jpg|JPG|gif|GIF|png|PNG)$ - [F]
Published in: Linux

Looking for something? Find here!

Meet the Author

Web Geek, Tech Columnist
Amit Agarwal

Amit Agarwal is a Google Developer Expert in GSuite and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. Read more on Lifehacker and YourStory

Get in touch