View Full Version : Hot Link Blocking - mod rewrite
Purrsia
12-14-2005, 05:44 PM
I know how to make an htaccess file to deny folks from remotely accessing my files. In fact, I've been using that instead of the cpanel settings. Stick with the tried and true, right?
However, the kind of thing I'm using only produces a red x where the hotlink is attempted. I know there's another way of doing it to where you can actually have an image or file of your choice come up in place of the attempted-to-link-to image/file (usually a snarky image macro announcing the theif's bad taste) and it's called mod rewrite, but some servers don't allow it. I'm thinking since the command is apache based, this host won't allow it either? If so, is there a way I can do this here without using mod rewrite commands?
Thanks.
globalgf
12-14-2005, 09:20 PM
I don't know how but, try going to pixel2life.com they have many tutorials for everything.
lostinfr
12-15-2005, 08:17 AM
I had problems with this too both with htacess & in the c panel, the problem I had was that in Internet Explorer it was blocking images on my site as well, eventually after trying lots of different codes this worked for me:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|swf)$ - [F,NC]
You can change the file extensions above to suit.
And this is the same but shows an image of your choice i.e. "No Hotlinking!" Just create your image and name it nohotlink.jpg (the path in the code is /images)
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?lost-in-france.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.lost-in-france.com/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|swf)$ images/nohotlink.jpg [L]
And a useful site to test if it's working:
http://altlab.com/hotlinkchecker.php
Purrsia
12-15-2005, 02:37 PM
Thanks, everyone!
After a few attempts to get it to function as I desired, it's working great now. Allowing access for me and my other domains but blocking those not on the approved list. Awesome.
My previous host wouldn't allow mod rewrite in an htaccess file, so here's one more reason to love siteground :)
Purrsia
12-17-2005, 11:43 AM
Sorry for the double post but I wasn't right about the success of the document as I thought I was.
Ok, here's my htaccess file code:
ErrorDocument 404 /errorpages/404.html
ErrorDocument 403 /errorpages/403.html
ErrorDocument 500 /errorpages/500.html
ErrorDocument 401 /errorpages/401.html
RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://purrsiathunder.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://purrsiathunder.org$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purrsiathunder.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purrsiathunder.org$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purrsiathunder.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purrsiathunder.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://voltron.purrsiathunder.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://voltron.purrsiathunder.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://jukebox.purrsiathunder.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://jukebox.purrsiathunder.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://fanlistings.purrsiathunder.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://fanlistings.purrsiathunder.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://purrsia.livejournal.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://purrsia.livejournal.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.livejournal.com/users/purrsia/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.livejournal.com/users/purrsia$ [NC]
RewriteCond %{HTTP_REFERER} !^http://htmlgear.lycos.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://htmlgear.lycos.com$ [NC]
RewriteRule .*\.(jpg|jpeg|JPEG|JPG|gif|GIF|png|bmp|zip)$ graphix/sightbeyondsight.GIF [L]
It works fine except for areas of my site where I use a javascript to flip through image files and use a button that will show the larger version of those images in another browswer window. Such as here (http://www.purrsiathunder.org/blueprints.php).
Now, if I just have an image embedded in a page and use a regular "target=_blank" html code to get the image to come up in a new window, there's no problem, such as on this page here (http://www.purrsiathunder.org/wildreclaiming.php)
I tried changing the settings in cpanel to allow for direct requests, and that did fix it as far as the java galleries went, but then either the image redirect no longer worked or hotlink protection died altogether. So I haven't had a lot of luck with cpanel settings. I turned off everything there and just uploaded my originally "successful" mod-rewrite version of my htaccess file. And yeah, it works except for that little problem with my javascript galleries. Is there something I can add to the above htaccess code to fix this without compromising the redirected block, or should I just find a new way to display those galleries?
Thanks. I've been beating my head against the desk trying to figure this out but this is also new territory for me.
Also, some visitors have been seeing my redirected image in place of *all* my site's images. For most, it's a simple matter of a page refresh as they're seeing an old cache of the page when I first tried this and my own domain was also blocked. But for a few, this is not successful. I read that mod rewrite can thwart people behind a firewall or proxy...is this true? I assume they would then have to change their computer settings somehow to view my site properly. Just thought I'd check on that too while I'm posting ;)