htaccess Folder Protection Allows Single Referrer

I was looking for a relatively quick and simple way to block anyone from accessing a folder of my products without coming from from a link from my website. I figured that an .htaccess file placed within a folder filled with my protected files was the way to go and I would just allow my domain as the only allowed exception.

I probably tried 20 different versions before this one worked for me.

Note:  I’m told this is not the “end all” of file protection and that the referrer variable can be faked via browser trickery.  So if you are looking for a perfect solution, this ain’t it!  However, it’s going to stop most trying to access your protected content.

<code>

## PREVENT HOTLINKING
SetEnvIfNoCase Referer “^http://www.YOURDOMAIN.com” good
SetEnvIfNoCase Referer “^$” good
<FilesMatch “\.(png|jpg|jpeg|gif|bmp|swf|flv|zip)$”>
Order Deny,Allow
Deny from all
Allow from env=good
ErrorDocument 403 https://www.YOURDOMAIN.com/your-error-message.html
</FilesMatch>

</code>

Of course, you’ll want to change YOURDOMAIN.

Good luck!

Brandon

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

You must be logged in to post a comment.