What is Image Hot linking?
To display an image on a website from another website. For example, you have created some stunning images on your website and another user uses those images on their website using your domain link. In this case whenever the other user’s website loads, The image is loaded from your website. This can increase the hosting cost for you.
This tutorial will help you to prevent image hotlinking on Apache using .htaccess.
Prevent Image Hot Linking
Create a .htaccess file under the document root of your website. Then add the following rules to the created .htaccess file. This will block all domains except example.com from hotlink images from your site.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?example.com [NC] RewriteRule \.(jpe?g|png|gif|bmp|tif)$ - [NC,F,L]
The above in .htaccess code will prevent other domains from linking images from your website. You can also show a blocked banner in place of the hot-linked image. To show the banner use the below rules in your .htaccess file.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?example.com [NC] RewriteRule \.(jpe?g|png|gif|bmp|tif) http://example.com/blocked.png [R,L]
Disable Image Hotlinking for Specific Domains
Sometimes you may need to block image hotlinking from some specific domains. It can be any domain or subdomain name. Use the following example code in the server .htaccess file. This will block image hotlinking for the domains blockthis.com and baddomain.net.
RewriteEngine on RewriteCond %{HTTP_REFERER} ^https?://(.+\.)?blockthis\.com [NC,OR] RewriteCond %{HTTP_REFERER} ^https?://(.+\.)?baddomain\.net [NC,OR] RewriteRule \.(jpe?g|png|gif|bmp|tif)$ - [NC,F,L]
Conclusion
In this tutorial, you have learned to prevent images to be hot linked by the unknown domains in the Apache server.
2 Comments
not working at all
What issue are you facing?