Stopping hotlinking from my site

Soldato
Joined
27 Oct 2003
Posts
4,996
Location
East Mids.
After looking through my web stats I noticed a site in Spain was using images from my site without asking. Can I make it so that my images can only be used on certain sites. I've heard about a .htaccess file but after a quick google, i'm now lost. Any help would be great thanks.
 
If you look in your hosting provider's control panel, you will probably find you have an option which will set this up for you automatically :).
 
If you look in your hosting provider's control panel, you will probably find you have an option which will set this up for you automatically :).

While this is true for the most part, not all hosts may provide it.

Either way http://www.workingwith.me.uk/articles/scripting/mod_rewrite is a good read.

Around a third of the way in the article specifically covers hotlinking and its prevention. It even shows you how to replace the image with something not very nice :p
 
So basically the code I need is

Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?somesite.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.somesite.com/nasty.gif [R,L]

So for example I would change it to

Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?forums.overclockers.co.uk/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.somesite.com/nasty.gif [R,L]

and any image posted here would be allowed?

Or have I got it wrong?
 
Back
Top Bottom