Developer forum

Forum » CMS - Standard features » Prevent hotlinking on images

Prevent hotlinking on images

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

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,
Adrian


Replies

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

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. 

<rewrite>
<rewriteMaps>
<rewriteMap name="Hotlink Whitelist">
<add key="some-future-url.mydwsite2.com" value="allow" />
</rewriteMap>
</rewriteMaps>
<rules>
<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="(.*)" />
</conditions>
<action type="Redirect" url="https://{C:3}/files/images/nohotlinking.jpg" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

Best Regards,

Scott
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Scott,

This is exactly what I was looking for.

Thank you very much.

Adrian

 

You must be logged in to post in the forum