Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Given this folder / file structure:

private/.htpasswd
public/.htaccess

... 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
add comment

3 Answers

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. –  fireeyedboy 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
add comment

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! –  fireeyedboy Sep 20 '11 at 21:55
add comment

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

/var/www/some/path/private

then

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. –  fireeyedboy Sep 20 '11 at 21:33
add comment

Your Answer

 
discard

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.