htaccess 从基本身份验证中排除多个 url
htaccess exclude multiple url from Basic Auth
您好,我需要在测试阶段保护我的应用程序。
我读过这个 post 关于从基本验证中排除一个 url
但我想排除 2 urls :
/api/*
/oauth/v2/token
因此,除了那两个 url,即 public 之外,整个应用程序都将受到保护。否则我无法访问我的 api 路线。
我现在的 .htaccess 是:
# Protect the app with password
AuthUserFile /home/master/public_html/web/.htpasswd
AuthName "Protected"
AuthType Basic
Require valid-user
所以我猜我应该需要某种排序或正则表达式:
SetEnvIf Request_URI ^/api/ noauth=1
我怎样才能拥有 OR 条件?
尝试:
SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1
您可以排除 uris,只需使用横线将它们分开 |
你可以换行Require
inside another directive, like Directory
or Location
<Location /api/>
Require all granted
</Location>
<Location /oauth/v2/token>
Require all granted
</Location>
没有问,但是 Getting it working 说了 .htpasswd
This file should be placed somewhere not accessible from the web. This is so that folks cannot download the password file.
所以你不应该把 .htpasswd 放在 public_html
.
Apache 2.4 Auth/Access 控件自 2.2 以来已更改。
这是新语法:
AuthType Basic
AuthUserFile /home/master/public_html/web/.htpasswd
AuthName "Protected"
SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1
<RequireAny>
Require env noauth
Require env REDIRECT_noauth
Require valid-user
</RequireAny>
您好,我需要在测试阶段保护我的应用程序。
我读过这个 post 关于从基本验证中排除一个 url
但我想排除 2 urls :
/api/*
/oauth/v2/token
因此,除了那两个 url,即 public 之外,整个应用程序都将受到保护。否则我无法访问我的 api 路线。
我现在的 .htaccess 是:
# Protect the app with password
AuthUserFile /home/master/public_html/web/.htpasswd
AuthName "Protected"
AuthType Basic
Require valid-user
所以我猜我应该需要某种排序或正则表达式:
SetEnvIf Request_URI ^/api/ noauth=1
我怎样才能拥有 OR 条件?
尝试:
SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1
您可以排除 uris,只需使用横线将它们分开 |
你可以换行Require
inside another directive, like Directory
or Location
<Location /api/>
Require all granted
</Location>
<Location /oauth/v2/token>
Require all granted
</Location>
没有问,但是 Getting it working 说了 .htpasswd
This file should be placed somewhere not accessible from the web. This is so that folks cannot download the password file.
所以你不应该把 .htpasswd 放在 public_html
.
Apache 2.4 Auth/Access 控件自 2.2 以来已更改。 这是新语法:
AuthType Basic
AuthUserFile /home/master/public_html/web/.htpasswd
AuthName "Protected"
SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1
<RequireAny>
Require env noauth
Require env REDIRECT_noauth
Require valid-user
</RequireAny>