限制对api url以外的根文件夹htpasswd的访问

时间:2018-01-15 13:27:29

标签: .htaccess .htpasswd

我知道这里已经提出了这个问题:htaccess exclude multiple url from Basic Auth但在答案中,我没有找到解决方案我的问题,所以我在这里重新开始。

我想阻止使用htpasswd访问项目的根目录,除了api url(它不是现有文件夹,而是由index.php控制的端点)。

到目前为止,这是我用于htaccess的内容:

<Location />
AuthType Basic
AuthName "Auth Required"
AuthUserFile /home/user/.htpasswd
Require valid-user
SetEnvIf Request_URI "(api|oauth)$" allow
Order allow,deny
Allow from env=allow
Satisfy any
</Location>

=&GT; htpasswd有效,但它也阻止/ api / xxx。

有人可以帮我纠正吗?

1 个答案:

答案 0 :(得分:0)

你可以像这样使用它:

SetEnvIf Request_URI "/(api|oauth)(/.*)?$" allow

AuthType Basic
AuthName "Auth Required"
AuthUserFile /home/user/.htpasswd
Require valid-user
Satisfy any
Order      deny,allow
Deny from  all
Allow from env=allow

Also note that the <Location> directive is not allowed in .htaccess.

相关问题