Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Apache server with password-protected web directory. That directory has a sub-directory, which requires another password, but anyone who can access the sub-directory should have access to the parent directory as well. That is:

  • /stuff - users "stuff" and "admin" allowed
  • /stuff/admin - only user "admin" allowed

So I've set it up that way in the Apache config:

<Directory "/stuff">
   [AuthType Basic, AuthName, etc.]
   Require user stuff
   Require user admin

<Directory "/stuff/admin">
   [AuthType Basic, AuthName, etc.]
   Require user admin

This works in the sense that I can browse to /stuff and log in as either "admin" or "stuff". However, the pages in /stuff/admin references some images from the parent directory. I find that when I browse directly to /stuff/admin and log in as "admin" the browser still prompts me for another password to load those images. (I know it's the prompt for /stuff, because the AuthName value is different.)

How do I avoid this and allow a user who has access to /stuff/admin to just log in once (as "admin"), not twice?

share|improve this question
up vote 5 down vote accepted

The problem turned out to be the different AuthName value for the two directories. I thought that its sole purpose is to provide a meaningful prompt to the user. Having read the documentation again, it turns out it has another purpose: the browser will automatically try the same credentials for directories with the same AuthName.

So what was happening in my case was that after having authenticated to /stuff/admin the browser would request /stuff/something-else, it would get a "401 Unauthorized" response, but it wouldn't even try the same credentials. After I changed the AuthName to be the same it automatically responded to the 401 by retrying with the "admin" username that I previously authenticated with, which worked.

share|improve this answer
+1, but this seems to be browser-dependent (worst on Firefox). I had this when using multiple .htaccess files, rather than the config file. AuthName fixed it. – EML May 25 '14 at 14:42

Have you tried reversing the order of the stanzas in your htaccess so that the more specific case is first? This may affect the matching and solve your double prompting problem.

Another thing to check is if you can use Realms or Groups to simplify, perhaps to specifying that multiple containers use the same authentication backend.

This (AAA) is different between Apache and Apache2 so check what you have. Here are both sets of docs:



share|improve this answer
Not quite, but you pointed me in the right direction: AuthName was the problem - see my answer. – EMP Oct 3 '09 at 1:29

I haven't tried it, but would it work to change them both to require valid-user and point the admin .htaccess to a group .htpasswd file which was the admin subset and the base directory .htaccess to a .htpasswd file with the larger superset?

share|improve this answer

I believe when you list things on separate lines there is an implied "and". Try listing the users on the same line for an implied "or":

<Directory "/stuff">
   [AuthType Basic, AuthName, etc.]
   Require user stuff admin
share|improve this answer
Thanks, but this didn't help - it still behaves the same. – EMP Oct 3 '09 at 1:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.