我可以使用 htaccess 密码保护 apache 中的位置(不是目录)吗?

dim*_*vic 7 authentication .htaccess htpasswd apache-2.2

我在 apache 配置中使用了这样的代码来保护带有密码的位置

<Location ~ "/admin.*">
    AuthType Basic
    AuthName "Protected Area"
    AuthUserFile /home/user/public_html/.htpasswd
    Require valid-user
</Location>
Run Code Online (Sandbox Code Playgroud)

有没有办法使用 htaccess 文件做同样的事情?

我想保护的位置在文件系统上并不真正存在,由于 mod_rewrite,它的位置可用

Gop*_*poi 0

是的,可以这样做,将 htaccess 放入您想要控制访问的文件中。输入与配置文件中相同的文本。确保您的conf 文件将读取.htaccess。

  • htaccess 不接受 &lt;Location&gt; 标签,它的上下文是“服务器配置,虚拟主机”http://httpd.apache.org/docs/current/mod/core.html#location (2认同)