.htaccess deny access to all except to one file

Viewed 47184

How can I deny access to a complete folder and sub-folders, with the exception of one file? That file is: toon.php and resides in the same folder.

8 Answers
AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic
AuthUserFile .htpasswd
require valid-user


<Files "toon.php">
Allow from all
Satisfy Any

</Files>

Works for me. Dont' forget to configure the .htpasswd file.

There is a related scenario in WordPress admin where you may want to limit the access to specific IPs, but leave access for some specific files used by plugins:

## /wp-admin/.htaccess ##
Deny from all
allow from 88.222.123.88 #Home 
allow from 88.111.211.77 #Office

<Files "admin-ajax.php">
     Allow from All
</Files>

WordPress-specific configuration for Private Area using HTTP password:

AuthName "Private Area"
AuthType Basic
AuthUserFile .htpasswd
require valid-user

<Files "admin-ajax.php">
Allow from all
Satisfy Any
</Files>
Related