排除受保護的子 URL 在 Apache 2.4 上不起作用?

排除受保護的子 URL 在 Apache 2.4 上不起作用?

我嘗試從受保護的網站中排除子網址“/shop/api”。它在 Apache/2.2.15 上的不同伺服器上運作良好,但現在在 Apache/2.4.7 上運作不正常?它始終要求基本身份驗證。知道我做錯了什麼嗎?

AuthType Basic
AuthName 'Authentication required'
AuthUserFile /var/www/vhosts/pwd/.htpasswd

# Allow access to excluded diretories
SetEnvIf Request_URI ^/shop/api/  noauth=1
Order deny,allow
Satisfy any
Deny from all
Require valid-user
Allow from env=noauth

答案1

正如「lain」所指出的 apache 2.4 Auth/存取控制內容自2.2以來發生了變化。所以我需要修改如下:

AuthType Basic
AuthName 'Authentication required'
AuthUserFile /var/www/vhosts/pwd/.htpasswd
# Allow access to excluded directories
SetEnvIf Request_URI /shop/api  noauth=1
<RequireAny>
  Require env noauth
  Require env REDIRECT_noauth
  Require valid-user
</RequireAny>

另外我必須添加,Require env REDIRECT_noauth因為 PHP 正在使用一些重定向,這會保留 env 變數noauth

相關內容