.htaccess protects directory passwords without an index file

How can I password protect directories that do not have a file index? I want only part of the index to be password protected, not files inside.

For instance:

http://www.example.com/foo/            Password required
http://www.example.com/foo/bar.html    No password required

I can do those forbiddenon

Options -Indexes

but I don’t want them to be banned, instead I want them to require a password.

Is it possible? Thank.

+3
source share
1 answer

I figured out how to do it !: D

First Place in a PHP-generated directory for those who do not have an index page:

DirectoryIndex default.php index.php index.html /php_directory.php

Then just password protect the file php_directory.php!

AuthUserFile /full/path/here/.htpasswd
AuthType Basic
AuthName "Log in"

Thanks for your comments! (which helped me get to this)

+1
source

All Articles