Page 1 of 1

.htaccess - Allow access only to certain image files

Posted: Tue Sep 05, 2006 2:53 pm
by JustinK322
I have a directory full of images and for each image, there is a preview image. The images are named g1_p1.jpeg, g1_p2.jpeg, g1_p3.jpeg, etc. The preview images are named g1_p1_preview.jpeg, g1_p2_preview.jpeg, g1_p3_preview.jpeg, etc. All of these images are in a directory called "pics" which is a subdirectory of the directory "members". I would like to have the entire members directory password protected with .htaccess and .htpasswd. I can do this with no problem using this as my .htaccess file in the members directory:

Code: Select all

AuthName "Restricted Area" 
AuthType Basic
AuthUserFile "/home/httpd/vhosts/yourgirlfriendonthenet.com/httpdocs/test/members/.htpasswd"
require valid-user
I also have a sister directoy of "members" called "public". In this directory, I have a page on which I would like to use all of the preview images without having to use a password. I have not been able to accomplish this. As of now, I am using this as my .htaccess file:

Code: Select all

<FilesMatch "(g(\d)+_p(\d)+_preview\.(jpeg|jpg|gif|bmp))">
allow from all
</FilesMatch>

<FilesMatch "(g(\d)+_p(\d)+\.(jpeg|jpg|gif|bmp))">
AuthName "Restricted Area" 
AuthType Basic
AuthUserFile "/home/httpd/vhosts/yourgirlfriendonthenet.com/httpdocs/test/members/.htpasswd"
require valid-user
</FilesMatch>

<FilesMatch "*.php">
AuthName "Restricted Area" 
AuthType Basic
AuthUserFile "/home/httpd/vhosts/yourgirlfriendonthenet.com/httpdocs/test/members/.htpasswd"
require valid-user
</FilesMatch>
This requires a password for the image files, allows access to the preview files, and require a password for the *.php files in the members directory (All of the pages for the site end in .php).

What I would really like is to password proctect the entire members directory except for the image files whose names contain "_preview"

Any suggestions?

Posted: Tue Sep 05, 2006 3:40 pm
by feyd
Why not deny them all flat out then write a script to interface/tunnel to them for retrieval?