Htaccess: Prevent People Hotlinking Your Images
Here’s some Htaccess code that will prevent people from hotlinking images hosted on your server. Simply change the domain to yours and then apply the code to your .htaccess. It’s as easy as that.
1 2 3 | RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?brightcherry.co.uk [NC] RewriteRule \.(jpeg|jpg|gif|png)$ - [F] |
The code is basically saying that all jpg, gif and png files hosted on brightcherry.co.uk can only be displayed on brightcherry.co.uk. Anyone else that tries to hotlink it will see a X.
Why would you want to prevent people from hotlinking?
There are many reasons, but the main two I can think of are:
- Prevents copyright infringement
- Reduces data transfer. If someone hotlinks one of your images onto a website that receives heavy traffic, it will be your server that’s sending the data. That could specifically be costly for Admins that don’t have unlimited data transfer allowance.
brightcherry.co.uk
You should also care about caches of search engines because when people open it they’ll se X overthere too.