htaccess 文件引用转到 /etc/apache2,试图更改为相对

htaccess file references going to /etc/apache2, trying to change to relative

我的 .htaccess 文件中有以下内容:

AuthType Basic
AuthName "Secured"
AuthUserFile ../private/passwd
Require valid-user
Order allow,deny
Allow from env=unauthenticated
Satisfy any

来自 error.log 的问题是 Apache 说 "Could not open password file: /etc/apache2/passwd" - 这显然是我的 Apache root。

我如何为路径指定对 .htaccess 文件的相对引用?

而且可能非常重要,这可以只在 .htaccess 文件中完成吗?

如果是这样,回答问题 #2 会使解决方案更便携。

文档:AuthUserFile

The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.

所以我假设你的服务器根在 /etc/apache2/ 所以你的相对 URL: ./passwd 将相对于根,而 不是 你的 htaccess 文件所在的位置。因此,不可能使其可移植并相对于放置 htaccess 的位置。

此外,文档还说:

Security

Make sure that the AuthUserFile is stored outside the document tree of the web-server. Do not put it in the directory that it protects. Otherwise, clients may be able to download the AuthUserFile.

因此,将密码文件保存在提供内容的同一位置是个坏主意。