Developer forum

Forum » CMS - Standard features » Prevent hotlinking on images

Prevent hotlinking on images

Adrian Ursu Dynamicweb Employee
Adrian Ursu

Hi guys,

I have a B2C website that seems to be affected by spammy websites using their Image links as backlinks.

Is there any way I can prevent this? Some Robots rule or web.config or Url Rewrite?

Thank you,


Scott Forsyth Dynamicweb Employee
Scott Forsyth

Hi Adrian,

URL Rewrite is the way to go. Here's an example rule that I have for one of our projects. It looks like I planned for possible exceptions with the whitelist. You can leave that out if you don't have a need for it, or leave it in since it gives future flexibility. 

<rewriteMap name="Hotlink Whitelist">
<add key="" value="allow" />
<rule name="Prevent Hotlinking" stopProcessing="true">
<match url="(?:jpg|jpeg|png|gif|bmp|GetImage.ashx)" />
<conditions trackAllCaptures="true">
<add input="{HTTP_REFERER}" pattern="^https?://(.+?)/.*$" />
<add input="{Hotlink Whitelist:{C:1}}" pattern="allow" negate="true" />
<add input="{HTTP_HOST}|{C:1}" pattern="([^\|]+)\|\1" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="nohotlinking.jpg" negate="true" />
<add input="{HTTP_HOST}" pattern="(.*)" />
<action type="Redirect" url="https://{C:3}/files/images/nohotlinking.jpg" redirectType="Temporary" />

Best Regards,

Adrian Ursu Dynamicweb Employee
Adrian Ursu

Hi Scott,

This is exactly what I was looking for.

Thank you very much.



You must be logged in to post in the forum