在我的本地主机和实时网站上,我有不同的 .htaccess 指令,如下所示:
AuthUserFile /path/to/folder/.htpasswd
有没有办法动态指示 .htaccess 文件中的根目录,以便我不需要为本地主机和实时主机使用不同的 .htaccess 文件?
最佳答案
来自:http://httpd.apache.org/docs/2.2/en/mod/mod_authn_file.html#authuserfile :
File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.
所以解决方案之一是使用相对路径。您应该将 ../auth/.htpasswd
之类的内容与 Web 根目录之外的 auth 目录一起使用(例如,如果 .htaccess 位于您的 Web 根目录上)。
PS:%{DOCUMENT_ROOT} 只是一个 mod_rewrite 变量 AFAIK,因此您没有它用于 AuthUserFile 指令
关于Apache .htaccess 根目录变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7135533/