我有以下带有基本身份验证和 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