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

Given this folder / file structure:


... where public is the root folder of a virtual host in Apache, and private is its sibling folder:

How do I define a relative path for AuthUserFile in the .htaccess file, such that it is able to access /private/.htpasswd

I've tried:

AuthType Basic 
AuthUserFile ../private/.htpasswd
require valid-user

But that doesn't work, because it tries to find the file relative to the ServerRoot, in stead of relative the virtual host root.

I won't have access to the config file on the production server (shared host) and I don't want to define an absolute path, because my testing and production file system structures don't match.

Is it still possible to achieve what I want, given these conditions?

share|improve this question

You may use symlink on testing system, for example /srv/www/vhost/private/.htpasswd -> /var/www/vhost/private/.htpasswd. The first path need to be same as on production server. Then you will be able to use the same paths on both servers. Options FollowSymLinks may be required for this. I don't see any way to include config files not relatively to ServerRoot.

share|improve this answer
I'm gonna try and tinker with this a bit. My testing environment is a Windows environment though, so it probably won't work, but I'll give it a shot. Thanks. – Decent Dabbler Sep 20 '11 at 21:51
NTFS can make hard links, see this. To have similar paths on testing and production, you may create hardlink and specify file path relatively to ServerRoot. – Selivanov Pavel Sep 20 '11 at 21:57

If the symlink solution posted by Selivanov Pavel does not work, you could disable Auth* directives in .htaccess using ALlowOverride -AuthConfig (or disable .htaccess altogether) and move the Auth config to the Apache conf on your local machine only.

share|improve this answer
That's a nice alternative. I'll gonna try that out also. Thanks! – Decent Dabbler Sep 20 '11 at 21:55

Let's take an example.

Your application is located in /var/www/myApp on some Linux server

.htaccess : /var/www/myApp/.htaccess

htpasswdApp : /var/www/myApp/htpasswdApp. (You're free to use any name for .htpasswd file)

To use relative path in .htaccess:

AuthType Digest
AuthName myApp
AuthUserFile "htpasswdApp"
Require valid-user

But it will search for file in server_root directory. Not in document_root.

In out case, when application is located at /var/www/myApp :

document_root is /var/www/myApp

server_root is /etc/apache2 //(just in our example, because of we using the linux server)

You can redefine it in your apache configuration file ( /etc/apache2/apache2.conf), but I guess it's a bad idea.

So to use relative file path in your /var/www/myApp/.htaccess you should define the password's file in your server_root.

I prefer to do it by follow command:

sudo ln -s /var/www/myApp/htpasswdApp /etc/apache2/htpasswdApp

You're free to copy my command, use a hard link instead of symbol,or copy a file to your server_root.

share|improve this answer

Without a leading / then the path provided to AuthUserFile is relative to ServerRoot. Your private directory will have a path relative to ServerRoot so just provide that - given

ServerRoot /var/www

and a provate directory at



AuthUserFile some/path/private

should work.

share|improve this answer
Yeah I understand this, but since the file structure on my testing server and production server don't match, I'd have to edit .htaccess on the production server. Preferably I want to keep it as portable as possible. – Decent Dabbler Sep 20 '11 at 21:33

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.