DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Stopping hot linking

 6 Replies
 1 Subscribed to this topic
 40 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 25
New Around Here

If I put the following in my web.config, this will stop people hot linking any images on my site? Clearly I'd edit the domains to reflect my addy. Thanks for any help.




 
 
 
   
   
   
 

 



Senior Member
Posts: 1607
Senior Member
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

I haven't personally tried the method you're attempting, but I'd recommend a slightly different approach, if you're open to it...  

If you're using a WAF to protect your website, you should be able to easily enable this as a setting.  In Cloudflare, you can do this with their free plan.  (See below.)  The other benefit is that you get another layer of protection and a CDN that both help your website perform better for all visitors.  :)  

New Around Here
Posts: 25
New Around Here
I am using Mochahost as my host. I do not see a hot linking block on their control panel why I was looking for a more direct fix. I tried that code in my config file and sadly it did not work. Not sure why.
Growing Member
Posts: 55
Growing Member
Do you have forced https on the site? If so (which you should btw), the rule is only looking for http. See this article for rewrite rules which will work:

https://www.rewriteguide....nt-image-hotlinking/
New Around Here
Posts: 0
New Around Here

Hello,

I agree with Will that the solution Cloudflare offers (free) works very good but if you really want to do it your self use this:

<code><rewrite> <rules> <rule enabled="true" name="Block Hotlinking" stopprocessing="true"> <match url="(?:jpg|jpeg|png|gif|bmp)$"> <conditions logicalgrouping="MatchAll" trackallcaptures="false"> <add input="{HTTP_REFERER}" pattern="^https?://(.+?)/.*$"> <add input="{DomainsAllowList:{C:1}}" pattern="^block$"> <add input="{REQUEST_FILENAME}" negate="true" pattern="no-hotlink.png"> <add input="{REQUEST_URI}" negate="true" pattern=".*(hotlink-ok).*"> </add></add></add></add></conditions> <action appendquerystring="false" redirecttype="Temporary" type="Redirect" url="https://yourdomain.com/images/no-hotlink.png"> </action></match></rule> </rules> <rewritemaps> <rewritemap defaultvalue="block" name="DomainsAllowList"> <add key="www.server-essentials.com" value="allow"> <add key="www.bing.com" value="allow"> <add key="www.google.com" value="allow"> <add key="www.google.ch" value="allow"> </add></add></add></add></rewritemap> </rewritemaps> </rewrite></code>

New Around Here
Posts: 0
New Around Here

Hello,

I agree with Will that the solution Cloudflare offers (free) works very good but if you really want to do it your self use this:

 
     
       
         
         
           
           
           
           
         

         
       

     

     
       
         
         
         
         
       

     

   

<code><rewrite> <rules> <rule enabled="true" name="Block Hotlinking" stopprocessing="true"> <match url="(?:jpg|jpeg|png|gif|bmp)$"> <conditions logicalgrouping="MatchAll" trackallcaptures="false"> <add input="{HTTP_REFERER}" pattern="^https?://(.+?)/.*$"> <add input="{DomainsAllowList:{C:1}}" pattern="^block$"> <add input="{REQUEST_FILENAME}" negate="true" pattern="no-hotlink.png"> <add input="{REQUEST_URI}" negate="true" pattern=".*(hotlink-ok).*"> </add></add></add></add></conditions> <action appendquerystring="false" redirecttype="Temporary" type="Redirect" url="https://yourdomain.com/images/no-hotlink.png"> </action></match></rule> </rules> <rewritemaps> <rewritemap defaultvalue="block" name="DomainsAllowList"> <add key="www.server-essentials.com" value="allow"> <add key="www.bing.com" value="allow"> <add key="www.google.com" value="allow"> <add key="www.google.ch" value="allow"> </add></add></add></add></rewritemap> </rewritemaps> </rewrite></code>

New Around Here
Posts: 0
New Around Here

In addition to the above you can put rewriterules, outboundrules and rewritemaps in seperate files like:

        
            
       

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved