Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess password protect directory but allow image file types

Tags:

php

.htaccess

I need to password protect a directory with .htaccess, which I have successfully done. But the front end of the website was programmed to link to images within this password protected directory (not by me), but when a webpage tries to access those images it prompts the user to login.

Is it possible to password protect that directory, but allow any access to any image file type like *.jpg and *.gif?

My current .htaccess code is this:

AuthName "Secure Area"
AuthUserFile "/home/siteuser/.htpasswds/public_html/admin/passwd"
AuthType Basic
require valid-user

Thanks for any help!

like image 936
Kevin Avatar asked Jul 28 '11 17:07

Kevin


People also ask

Can image file be password protected?

Go to File > Save as > Select save option as PDF. Select the “More options” link underneath the file format box, then select the “Options” button from the box that pops up. Select the “Encrypt document with a password option,” then enter a password (twice) as prompted.

What is htaccess protection?

htaccess and . htpasswd files are protected from all external access. This is super important because you do not want anyone or anything to access these sensitive and powerful files. If you are unsure, or just want to be extra secure, continue reading to learn how to protect all of your .


1 Answers

AuthName "Secure Area"
AuthUserFile "/home/siteuser/.htpasswds/public_html/admin/passwd"
AuthType Basic
require valid-user
<FilesMatch "\.(png|jpe?g|gif)$">
  Satisfy Any
  Allow from all
</FilesMatch>

Edit to incorporate Shef's improvement

like image 196
Frank Farmer Avatar answered Oct 31 '22 21:10

Frank Farmer