blackhat
02-07-2003, 11:36 PM
I read the tutorial at javascriptkit.com on how to prevent hot linking, I used this code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/nasty.gif [R,L]
but I can't even see the pictures on my own server when using this code, so what do I need to add here to make it work?
Thanks in advance
Blackhat
MLReynolds
02-21-2003, 07:16 AM
Did you replace "mydomain.com" with your own domain name?
ie, "YourDomainName.com"
Also, I had to put in two lines, since I can be accessed with or without the "www."
Mine reads;
RewriteCond %{HTTP_REFERER} !^http://?michaelsplace.us/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?michaelsplace.us/.*$ [NC]
(although that's what I was told. I didn't try with just one line)
You don't need to use two different lines to specify www and non-www, MLR...try this instead:
RewriteCond %{HTTP_REFERER} !^http://([a-z0-9-]+\.)*yourdomain.*$ [NC]
That will pretty much match everything you need it to (www vs. non-www, virtual domains, different domain identifiers, etc.)
MLReynolds
02-21-2003, 06:51 PM
Thank you for the tip. I still have a problem with Google's cache files displaying properly. Text only displays. Not images or formatting.
Any Idea?
dragon
05-16-2003, 07:00 AM
On a similar note, I'm trying to set up htaccess to prevent hotlinking but allow images to be viewed from multiple locations, my primary website and a forum hosted by someone else. The forum is at http://users.boardnation.com/~dragon76n/ so here's what I used:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dragonshobbies.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(users\.)?boardnation.com/~dragon76n/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.dragonshobbies.com/dhminilogo.gif [R,L]
The problem was that it would still display my dhminilogo.gif on my forum.
Should I write out the address completely, instead of having users\. in parenthisis? (I just thought of this so I haven't had a chance to test it yet.) Or what should I do?
UPDATE:
RewriteCond %{HTTP_REFERER} !^http://users.boardnation.com/~dragon76n/.*$ [NC]
This code did work to allow my forum to get the images. I ended up putting it into the images folder though, instead of in the root folder.