Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Hotlink protection

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 954 Views
  • SuGuS
    Avatar
    Community Member
    6 Posts

    Hotlink protection Link to this post

    Where i must insert this 3 Lines in my htaccess....

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?somedomainname\.ch(/.*)?$ [NC]
    RewriteRule \.(bin|rar|zip|exe|ipsw|gif|jpg|GIF|JPG|jpeg|JPEG)$ http://www.somedomainname.ch/assets/sorry.gif [R,L]

    At the moment they are at this position. But they do not work.
    I would only protect all my Files from Hotlinking.

    ### SILVERSTRIPE START ###
    <Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Files>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # RewriteCond %{HTTP_HOST} ^somedomainname\.ch [nc]
    # RewriteRule (.*) http://www.somedomainname.ch/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?somedomainname\.ch(/.*)?$ [NC]
    RewriteRule \.(bin|rar|zip|exe|ipsw|gif|jpg|GIF|JPG|jpeg|JPEG)$ http://www.somedomainname.ch/assets/sorry.gif [R,L]
    </IfModule>
    ### SILVERSTRIPE END ###

    I would be very happy if some one can help me... because my Servertraffic is about 10GB /day only trought Hotlinking. ;-(

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Hotlink protection Link to this post

    You should place your rewrite rule above the SilverStripe rules, since these will match first and then your rule won't be executed at all.
    Your file should look like this:

    ### SILVERSTRIPE START ###
    <Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Files>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?somedomainname\.ch(/.*)?$ [NC]
    RewriteRule \.(bin|rar|zip|exe|ipsw|gif|jpg|jpeg)$ http://www.somedomainname.ch/assets/sorry.gif [NC,R,L]

    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    </IfModule>
    ### SILVERSTRIPE END ###

    You can also remove the uppercase file endings and add a NC (not-case-sensitive) to the rewrite-rule flags (as I did above).
    Be sure to alter the domain-name to match your domain, but I guess you know that

  • SuGuS
    Avatar
    Community Member
    6 Posts

    Re: Hotlink protection Link to this post

    Thanks alot for your Help.
    Now it works

    Cheers and i wish you a very good Day

    954 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.