【问题标题】:Except Basic Authentication for some urls directories / files in除了一些 urls 目录/文件的基本身份验证
【发布时间】:2023-02-24 20:21:57
【问题描述】:
我试图找出我的开发服务器中的一点。
我有 linux 服务器并在该服务器上具有基本身份验证。我正在尝试删除某些文件夹/文件的身份验证。我怎样才能做到这一点?
.htaccess 代码如下:
AuthName "Password Protected Area"
AuthType Basic
AuthUserFile /var/.password
Require valid-user
【问题讨论】:
标签:
.htaccess
basic-authentication
【解决方案1】:
根据 Apache 版本、您要允许的特定文件夹/文件以及系统的管理方式,您可以通过多种方式执行此操作。
例如,在 Apache 2.4 上,您可以将基本的 auth 指令放在 <If> 容器中,并在 URL 上使用取反的正则表达式/字符串比较:
<If "%{REQUEST_URI} !~ m#^/folder(/|$)# && %{REQUEST_URI} != '/foo/bar.thml'">
AuthName "Password Protected Area"
AuthType Basic
AuthUserFile /var/.password
Require valid-user
</If>
当 URL 路径不是以 /folder/ 开头(即允许其中的所有文件)并且不等于 /foo/bar.html(因此允许该特定文件)时,上面的 <If> 表达式是成功的。
参考: