Authenticated directory listing


#1

Hi,

I am hosting some pages at DH.
I know how to block directory listing for everyone:

“Options -Indexes” in the .htaccess file.

How can I make the server ask for authentication (like .htpasswd) and allow listing only on successful login?

Let me (try to) explain what I want to do…
If I go to http://mydomain.com/some-directory/ I want to be prompted for a password.
If the password is correct, I get the standard directory listing generated by Apache.
If the password is wrong I should get a 403 status code or an empty page.

BUT: the files in the directory must be accessible for everybody.
If I type http://mydomain.com/some-directory/some-file.jpg I should be able to see the pic without being prompted for a password.

I cannot use IP-based solutions.

Thank you in advance
EnPa

P.S.: sorry for my bad english…


#2

Does this help? http://wiki.dreamhost.com/index.php/Htaccess#Authentication_examples

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#3

Not really…

Here is what I want to do in “pseudo-code” :wink:

Someone goes to mydomain.com/directory/
Ask for password
If password wrong —> Options -Indexes
Else —> Options +Indexes

Nothing else!
Access to files should always be granted!

EnPa


#4

I’m not familiar with htaccess. But I don’t think you can do this with htaccess. It seems you need two htaccess files in two folders with the different settings.

If I understand correctly (I’ve mis-understood the questinos some time before), you want to apply different settings to users. You can use PHP authentication fuction to ask use to enter a password and redirect them to different folders. However, this may not be the solution you are looking for.

Let’s see what the htaccess experts suggest.

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#5

I’ve not tested this, but it may work using

<Files “”>
#You put your Auth things here

By specifying Auth section to be applicable only to files with no name, it should only work on the directory = directory linsting.

Please try and let us know.

...* I’d be happier if DH had free shared SSL and redundant server setup. ..*.
http://Hostwick.com/


#6

Thank you, Extras!

It works!

Thank you very much!

EnPa


#7

Your welcome.
And thank you for testing and reporting back. :slight_smile:

...* I’d be happier if DH had free shared SSL and redundant server setup. ..*.
http://Hostwick.com/