Prevent Hotlinking from Specific Sites Only
You want to prevent hot-linking.
But not ALL websites. Sometimes you don’t mind if someone hotlinks from a forum or a review about your product, etc. However there are those that you DO want to block.
You can use the code below and place it into your htaccess file.
I placed the code in the .htaccess file inside my images folder, to just protect that folder, and to keep things straight forward.
If you wish to send a differnt image to the offending website, change the last line to an image that is outside your domain, or in a folder a level above where your .htaccess file is located.
Example: If I placed the code in the .htaccess file inside http://example.com/images, then my “nohotlink.jpg” image should be located http://example.com/nohotlink.jpg (otherwise it will blocked by it’s own rule).
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.ca/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?abc\.net/ [NC]
RewriteRule .*\.(jpg|gif|bmp|png)$ http://example.com/nohotlink.jpg [L]
2 Responses to “Prevent Hotlinking from Specific Sites Only”
Comments
Read below or add a comment...
THANK YOU!
I’ve been trying all sorts of code from various sites and they all ended up making my links on other sites come up horribly wrong. Looking like I hotlinked from my own site TO my own site was especially embarassing.
This code worked. Thanks again.