Apache .htaccess 密码保护与相对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/858074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache .htaccess password protect with relative path
提问by Sabya
I want to create a .htaccess file in my DocumentRoot, so that the directory is password protected.
我想在我的 DocumentRoot 中创建一个 .htaccess 文件,以便该目录受密码保护。
But the password file, I want to specify by using the relative path of DocumentRoot.
但是密码文件,我想通过使用DocumentRoot的相对路径来指定。
So, if I am checking out the code in another system, it just works as it is. The password file will be part of my source control.
所以,如果我在另一个系统中检查代码,它就可以正常工作。密码文件将成为我的源代码管理的一部分。
How can I access the parent directory of the DocumentRoot from .htaccess file?
如何从 .htaccess 文件访问 DocumentRoot 的父目录?
回答by Gumbo
I don't think that's possible. The AuthUserFiledirectiverequires the file-path to be either absolute (thus from file system root) or relative from the server root.
我不认为那是可能的。该AuthUserFile指令要求文件路径是绝对的(因此来自文件系统根)或相对于服务器根。
回答by cweiske
The AuthUserFile paths are relative to the server root (/etc/apache2/on Debian), or absolute.
AuthUserFile 路径相对于服务器根目录(/etc/apache2/在 Debian 上)或绝对路径。
To take care of different servers, you can use IfDefinedirectives with different variables on each server - see my blog postabout that.
为了处理不同的服务器,您可以IfDefine在每个服务器上使用具有不同变量的指令 - 请参阅我的博客文章。

