HTTP Basic Auth排除单个文件

Bra*_*sen 16 regex authentication .htaccess

我的.htaccess文件的一部分看起来像这样 -

AuthUserFile /path/to/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user
Run Code Online (Sandbox Code Playgroud)

这样做需要对整个目录及其下面的目录进行基本HTTP身份验证.但是,我在该根目录thubservice.php中有一个文件,它不应该要求HTTP身份验证.

从我所看到的,我需要使用<FilesMatch />,但我无法弄清楚除了给定文件之外的所有模式.

tal*_*ric 33

AuthUserFile /path/to/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user
<Files "thubservice.php">
    Satisfy Any
    Allow from all
</Files>
Run Code Online (Sandbox Code Playgroud)

  • +1 我正在输入的内容。你*可以*使用像`&lt;FilesMatch "^(?!thubservice\.php)"&gt;`这样的负前瞻来做,但它可能效率较低。在需要之前,我们不要将正则表达式拖入其中。 (2认同)