Log in

View Full Version : Prevent hotlinking -in a folder- using htaccess



rctxtreme
07-30-2007, 07:34 AM
I need to prevent hotlinking to all zips in a folder using htaccess, and redirect the result to a page.

I also need all images in that same folder to show up a "No hotlinking" image.

ddadmin
07-30-2007, 11:11 PM
You can't really prevent hotlinking of zip files, as they are never really hotlinked, unlike images. Zip files are always just linked to by other sites. If you're looking to stop that, you need to find a way to dynamically serve up the zip files using CGI or PHP. There are scripts out there that do that, but it's not within the capability of .htaccess.

To prevent hot linking on images inside a folder on your site, insert the below code into a blank .htaccess file, and upload it to that folder (in ASCII):


## DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourotherdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|zip)$ - [F]