我已经使用 htaccess 文件添加了 htpasswd 保护进行身份验证,现在我想绕过 www.website.com
和 www.website.com/index.php
的身份验证这两个网址都在访问 index.php 文件。通过使用下面的 htaccess 文件,我允许了 index.php 并且我能够绕过 www.website.com/index.php
url 但不能绕过 www.website.com
我的 htaccess 文件是:
# set an environtment variable "noauth" if the request starts with "/callbacks/"
SetEnvIf Request_URI ^/index.php noauth=1
AuthType Basic
AuthName "RESTRICTED"
#AuthName "Restricted Area"
AuthUserFile "/path/to/.htpasswd"
require valid-user
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ /file.php?show=all&name=$1 [L]
# Here is where we allow/deny
Order Deny,Allow
Satisfy any
Deny from all
Require valid-user
Allow from env=noauth
最佳答案
我相信第二个参数只是使用常规正则表达式。也许您可以将 index.php 设为可选。
SetEnvIf Request_URI "^/(index\.php)?$" noauth=1
还没有测试过。
关于php - 使用 index.php 和不使用它绕过 url 的 htpasswd 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29279039/