How to disable file hotlinking in Apache with .htaccess

October 26, 2018

If you want to ensure that every image requested comes with a HTTP referrer of your own site's URL then this anti image hotlinking .htaccess rule will help you out:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YOURSITE.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

Don't forget that you will probably need to enable the rewrite engine for these rules to work. Click the button below to find out how to do this.