How do I prevent hotlinking of my photos?

How do I prevent hotlinking of my photos?

By putting the following code in your .htaccess you prevent hotlinking:

RewriteEngine OnRewriteCond
%{HTTP_REFERER} !^https://(www.)?domainname.com [NC]
RewriteCond %{HTTP_REFER} !^$RewriteCond
%{HTTP_REFER} ^https://.*$RewriteRule
.(jpe?g|gif|bmp|png)$ /example/picture.gif [L]



For the web.config, you can use the following example:




name="Prevent hotlinking">
url=".*.(jpg|jpeg|png|gif|bmp)$"/>

input="{HTTP_REFERER}" pattern="^$" negate="true"/>
input="{HTTP_REFERER}" pattern="^https://(www.)?domainname.com/.*$" negate="true"/>

type="Rewrite" url="/example/picture.gif" appendQueryString="false"/>