Derek 朕會功夫
Derek 朕會功夫

Reputation: 94319

.htaccess password protect directories with no index file

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

For example:

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

I can make those forbidden by

Options -Indexes

but I don't want them to be forbidden, instead I want them to require a password.

Is that possible? Thanks.

Upvotes: 3

Views: 1414

Answers (1)

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94319

I have figured it out how to do it! :D

First Put in a PHP-generated directory for those without any index page:

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

Then just password-protect the php_directory.php file!

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

Thank you for all your comments! (which helped me to get to this)

Upvotes: 1

Related Questions