danbae danbae - 3 years ago 208
Apache Configuration Question

Entering AuthUserFile info in .htaccess when root path is dynamic

I'm trying to follow the instructions on http://www.4webhelp.net/tutorials/misc/htaccess.php in order to create a password file placed outside of the web root and use it in conjunction with .htaccess. The problem I can't solve here is that the

info in .htaccess is supposed to be an absolute path to the server root. I am using a server provided by a web hosting company and I found using
<?php echo $_SERVER['DOCUMENT_ROOT']; ?>
that the complete path to my web root looks something like
is stuff determined by the web host and, importantly, subject to change without notice. In PHP I can of course generate a path that always is correct using
. But .htaccess is not written in PHP. Is there a similar way to obtain the server root path upstream of the web root dynamically using the syntax of .htaccess?

Answer Source

From the manual:

File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.

You should give either an absolute path or a relative one to the server root. Neither would solve your problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download