Forum Moderators: phranque
I have the following .htaccess file on my website#1:
Options +FollowSymLinks
AuthPAM_Enabled off
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.net/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\..*(www\.)?mydomain\.net/ [NC]
RewriteCond %{HTTP_REFERER}!^http://babel\.altavista\.com/.*(www\.)?mydomain\.net/ [NC]
RewriteRule \.(gif¦ico¦jpg¦jpeg¦bmp¦wmf¦mid¦rmi¦rm¦ram¦au¦wav¦art¦img)$ [other-domain.com...] [NC,R,L]
and nothing else.
From an other PC than mine, I load my website#2 which contain direct links to website#1, say, with good.gif. The PC I use never visited website#1 and #2.
For the first load of a page on website#2, the Rewrite image boom.gif appears. It means that .htaccess works and good.gif is blocked.
If I re-load this page the real image good.gif appears. Others re-load go the same way.
How is it possible than .htaccess works perfectly the first time and doesn't work the second?
You should look at your raw server logs - I suspect you'll find that the second access -- the reload -- does not provide a referrer. Therefore, it bypasses your rewriterule because of the first RewriteCond.
HTTP_REFERER is unreliable because browsers don't always provide it and caching proxies and firewalls often block it or modify it. The code you have is the best you can do to make it difficult to hot-link images. Amateur hotlinkers will give up and go look for an easier target. The determined ones will have to be foiled by other means, such as by dynamically changing your image directory name and/or image links on a daily basis or by using other tricks.
Jim
As my website is in HTML and not in PHP, I don't see a good solution to resolve changing dynamically images directory.
As there is not a lot of others sites which make hotlinks with mine, I'm wondering if I am going to exclude them only by the domain name.
Do you have a script to exclude domains names from my image directory (http://www.otherdomain.com/ exclude from [mydomain.com...] )