Forum Moderators: phranque

Message Too Old, No Replies

protecting images in folder with htaccess

         

datto510

2:19 am on Sep 6, 2010 (gmt 0)

10+ Year Member



Hello,

I have an images in a directory that I want to protect from viewing by people finding out the direct link to the images.

I have a couple of ideas on how to do this, but cant seem to find a solution.

- only allow the images to be viewed when called via php
- automatically redirect the browser to another file eg index file when somebody tries to call a jpg file in the browser

I have tried a lot of rewrite codes but nothing will block the original images but still let the php file call them.

any ideas ?
Cheers.

Brett_Tabke

4:05 am on Sep 6, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Look into blocking via referrals.

Brett_Tabke

11:38 am on Sep 6, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]