Apache .htaccess 根目录变量?

标签 apache .htaccess

在我的本地主机和实时网站上,我有不同的 .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/

相关文章:

apache - 在 apache 中设置基本的 Web 代理

apache - .htaccess 仅将 root ("/") 重定向到子文件夹

Apache 无法在 Ubuntu 上的 AMPPS 中启动

php - Apache 后备资源配置

php - 如何将用户重定向到另一个域 .htaccess

php - 如何在服务器的htaccess中更改php版本

.htaccess - 如何根据获取环境变量动态设置AngularjS基本URL?

.htaccess - 使用 .htaccess 覆盖现有的 "noindex, nofollow"X-Robots-Tag header ?

php - 如何在 Web 服务器行为中更改文档根目录?

java - 如何在eclipse中导入src项目