Remove password protection from a subdirectory with Apache
Posted June 30th, 2010 in Apache
When a directory is password protected with Apache either with a .htaccess file or in the main Apache configuration, all subdirectories are also password protected. This post shows how to remove password protection from a subdirectory and from an individual file.
Removing password protection for a directory
If the directory /var/www/mysite/private is password protected and we want to make the subdirectory /var/www/mysite/private/public available without a password then create a new .htaccess file in that subdirectory that contains this:
Satisfy any
To do this in the main Apache configuration using <Directory>:
<Directory /var/www/mysite/private/public>
Satisfy any
</Directory>
or in a <Location> block:
<Location /private/public>
Satisfy any
</Location>
Removing password protection for a file
Add this to your .htaccess file to allow access to the file named e.g. public.html:
<Files public.html>
Satisfy any
</Files>
<Files> can be put within a <Directory> block in the main Apache configuration so to protect private and allow access to public.html you could do this:
<Directory /var/www/mysite/private>
AuthUserFile /path/to/.htpasswd
AuthName "Restricted Access"
AuthType Basic
require user [username]
<Files public.html>
Satisfy any
</Files>
</Directory>
Note that this will match any file named public.html under that directory. You could instead use <Files ~ ...> or <FilesMatch> which make the filename argument a regular expression to be more certain of matching the exact file. Me, I find it easier to just do it with an .htaccess file :)
Related posts:
- Password protection with Apache but allow from an IP address (Wednesday, August 11th 2010)
- Password protect a directory with Apache (Tuesday, June 29th 2010)
- Howto Restart Apache (Wednesday, December 22nd 2004)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

