WordPress.org

Forums

Hotlink Protection - Multi Site (8 posts)

  1. GrayHunter
    Member
    Posted 7 months ago #

    Hello,
    I would like to set a hotlink protection (via htaccess) but need your help.
    There is a long article (http://perishablepress.com/creating-the-ultimate-htaccess-anti-hotlinking-strategy/) where I found 2 nice codes. Here they are:

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER}     !^$
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$           [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\. [NC]
     RewriteRule \.(gif|jpe?g?|png)$                             - [F,NC,L]
    </ifModule>
    
    # hotlink protection via stupid htaccess tricks
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER} !^$
     RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.tld/.*$ [NC]
     RewriteRule .*\.(gif|jpg)$ http://www.domain.tld/eatme.jpe   [R,NC,L]
    </ifModule>

    QUESTIONS:
    Could you pls connect them to get this:
    1) Not [anything].domain.[anything] but [anything].domain.com
    2) This should work for domain mapped also (for sub-sites).
    3) The result of the "theft" should be one definite picture (http://domain.com/image-stop-hotlinking.jpg).

  2. Sure

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER}     !^$
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$               [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?(domain.com|mappeddomain.com|anotherdomain.com) [NC]
     RewriteRule \.(gif|jpe?g?|png)$                                 - [F,NC,L]
    </ifModule>
  3. GrayHunter
    Member
    Posted 7 months ago #

    Thank you, but
    2) new domains should not be added manually - it's impossible, there are lots of them new every day...
    3) I can't find this in your code...

  4. You can't magically automate #2 unless you write a script to update your .htaccess every time you add a new domain. It's just what it is.

    IMO #3 is a silly idea. It's just going to cause you more bandwidth so no one bothers with it. But if you insist, the last RewriteRule becomes this:

    RewriteRule .*\.(gif|jpe?g?|png)$ http://www.domain.tld/eatme.jpe   [R,NC,L]
  5. GrayHunter
    Member
    Posted 7 months ago #

    2) I see... may be there is such plugin anywhere?
    Or is it possible to protect only the main site for example?

    3) Ok, thx!

  6. Maybe. Not one I know of, though.

    If you only want to protect the main site, you'd change the RewriteCond %{HTTP_REFERER} bit to check for JUST the main site.

  7. GrayHunter
    Member
    Posted 7 months ago #

    Good, but could you give me the full code pls? Let the main site domain be domain.com.

  8. Should be this:

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com  [NC]
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$               [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?(domain.com|mappeddomain.com|anotherdomain.com) [NC]
     RewriteRule \.(gif|jpe?g?|png)$                                 - [F,NC,L]
    </ifModule>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.