0

我有以下带有基本身份验证和 URL 重写的 .htaccess 文件。我需要禁用特定路径的基本身份验证(例如,'/openaccess'),但重写首先发生,所以我无法使用 SetEnvIf 禁用身份验证。我找到的最接近的是这个答案,但它在 Apache 2.4.34 上对我不起作用。

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /path/to/.htpasswd
Require valid-user
4

1 回答 1

0

以下似乎有效:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /path/to/.htpasswd

SetEnvIf Request_URI /openaccess  noauth=1

<RequireAny>
  Require env noauth
  Require env REDIRECT_noauth
  Require valid-user
</RequireAny>
于 2020-03-07T10:08:55.680 回答