Forum Moderators: phranque
I'm trying to implement hotlink prevention to any graphic on my domain except from my site and one other site. This is what I have in my htaccess file:
AddHandler server-parsed .htm
Options +Includes -Indexes
# make .mydomain have a www in front of it
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
# block hotlinkers except for my site and another site
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com(/)?.*$ [NC[b],OR]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?OtherDomainIwantToAllow.com(/)?.*$ [NC][/b]
RewriteRule \.(gif¦jpg¦jpeg¦bmp)$ http://www.mydomain.com/hotlink.jpg [R,NC]
I've flushed my cache, Ctrl-Refreshed my browser, tried it on different computers, tried with different graphics, viewed my graphics from a couple of different external sites, etc. on almost every testing attempt.
I think I'll go down to the wig shop now, since I've pulled out most of my hair. Thanks for any insight you can provide!
Welcome to WebmasterWorld!
The problem is likely one of an infinite loop, since the hotlinker will be redirected to hotlink,jpg, but your rule will redirect that redirected request, too. So, you need to exclude requests for your hotlink.jpg image from being redirected.
There is also a logic error in the code and some "bad form" that should be cleaned-up.
Options +FollowSymLinks
RewriteEngine on
RewriteRule %{REQUEST_URI} !^/hotlink\.jpg$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [b][NC][/b]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?OtherDomainIwantToAllow\.com [NC]
RewriteRule \.(gif¦jpe?g¦bmp)$ /hotlink.jpg [NC]
Hopefully, that'll help you keep your hair. If not, check the references cited in our charter, and if that fails, I'm sure some of our members here are marketing hair-restoration products... ;)
Jim
I'll give this a try. Thank you very much for your quick assistance. Too bad I already spent $49.99 on a hair piece. :D I guess it'll grow back in time.
[Edit] Spoke too soon on part of this. Was dealing with a cache issue on other images still showing up, but the hotlink.jpg is still a no show at this point. If all that it will do will display a red X or empty image placeholder instead of the hotlink.jpg, I guess I can live with that. Still, the hotlink.jpg would have been a nice feature. Thanks again, Jim! I'll send you a bottle of hair tonic as a reward.[/edit]