Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Hotlink protection


Go to End


3 Posts   1672 Views

Avatar
SuGuS

Community Member, 6 Posts

5 May 2009 at 8:19pm

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. ;-(

Avatar
bummzack

Community Member, 904 Posts

7 May 2009 at 6:04am

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 :)

Avatar
SuGuS

Community Member, 6 Posts

10 May 2009 at 10:00pm

Thanks alot for your Help.
Now it works

Cheers and i wish you a very good Day