Welcome to Apache Prevent Hotlinking Linux PMC Tactical.
If you are grateful for all the work PMC has done in the past 25 years, use Support PMC page.
Apache Prevent / Block Image / File Hotlinking
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 to hotlink images from your site.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?example.com [NC] RewriteRule \.(jpg|png)$ - [NC,F,L]
You can also show a blocked banner in place of the hot-linked image. To show the banner use below rules in your .htaccess file.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?example.com [NC] RewriteRule \.(jpg|png) http://example.com/blocked.png [R,L]