Forum Moderators: phranque
SetEnvIfNoCase Referer "^http://(www.)?mydomain.com" spam_ref=1
SetEnvIfNoCase Referer "^http://(www.)?google.com" spam_ref=2
<FilesMatch "(.*)">
order deny,allow
deny from all
Allow from env=spam_ref
</FilesMatch>
Thanks.
Also, be aware that anyone typing-in your URL or clicking on a link created by JavaScript will not send a referrer. Therefore, you need to allow blank referrers as well.
Jim
I'm just hoping that you put that code into an image subdirectory, and didn't mention that fact here. Otherwise, the answer to you original question is, "No, that code will completely block access to everything on your site, except for accesses by googlebot and referrals from your own domain. But those own-domain referrals will never happen, because it will be impossible to initially enter your domain with that code in place."
If you have not seen that behavior, be sure to completely-flush your browser cache before starting a test run.
You should always flush your cache before testing any change to your server config, and flush it again after changing any aspect of the request that your code tests for. For example, flush cache, check that image displays on your own pages, flush cache, check that image does not appear on hotlinking page. If you don't flush your cache, then your browser will show the image in both cases, because you've allowed the image to be cached from the successful on-site request, and without a cache flush, the browser will use that cached image, and display it on the hotlinking page as well.
Jim
Referrers should always be all-lowercase, and I'd be very suspicious of one that wasn't.
All literal periods in regular-expressions patterns should be escaped.
If you want to protect all files, then there is no need for the FilesMatch container.
You also will want to allow blank referrers, because a good number of legitimate requests will not come with a Referer header due to browser and/or "security software" settings, and the settings of caching proxies in the client's ISP network, e.g. AOL and Earthlink.
While allowing blank referrers opens a "hole" in the hotlink protection, it is one we must accept in order to prevent blocking many legitimate client requests.
Taking all that into account:
SetEnvIf Referer "^http://(www.)?mydomain\.com" spam_ref=1
SetEnvIf Referer "^$" spam_ref=3
SetEnvIf Referer "^http://(www.)?google\.com" spam_ref=2
#
Order deny,allow
Deny from all
Allow from env=spam_ref
Jim