我在开发服务器上有一个基本身份验证设置.它是在我的httpd.conf文件中为网站的VirtualHost设置的.我必须将它设置为排除某些目录,这些目录没有引起任何问题并且一切正常.
问题在于排除已通过文件中的mod_rewrite规则的URL .htaccess.我的设置是我有所有URL通过我的index.php文件,并从那里找到并运行相关的代码.我尝试添加我想要排除的URL(/businesses/upload_logo),就像我做其他人一样,但它仍然需要身份验证.这就是我目前拥有的:
...
<Location />
SetEnvIf Request_URI "/businesses/upload_logo" noauth=1
SetEnvIf Request_URI "/api/.*" noauth=1
AuthType Basic
AuthName "Private"
AuthUserFile ****
Require valid-user
Order deny,allow
Satisfy any
Deny from all
Allow from env=noauth
</Location>
....
Run Code Online (Sandbox Code Playgroud)
我在这里和这里找到了与我类似的问题,但答案只给了我正在尝试的东西.
我也想过其他可能的解决方案,但这些都是最后的选择.我想看看我现在的做法是否可行:
.htaccess文件中
SetEnvIf HOST ...但我想看看它是否可以这样修复或不首先修复.该mod_rewrite规则:
...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L,QSA]
Run Code Online (Sandbox Code Playgroud) 我正在尝试排除路径(URI)被基本的http身份验证阻止.路径是/ rest(http://example.com/rest)并表示cakephp 3应用程序的控制器.它不是一个真正的文件,而是一个由重写条件重写的路径,并由webroot目录中的index.php处理.
这是重写规则:
/var/www/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
/var/www/webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我正在运行apache 2.4并尝试了不同的配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/webroot
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
</Directory>
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
Require expr %{REQUEST_URI} =~ m#/rest/.*#
Require expr %{REQUEST_URI} =~ m#/index.php/rest/.*#
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined …Run Code Online (Sandbox Code Playgroud) apache .htaccess mod-rewrite basic-authentication cakephp-3.0
您好,我需要在测试阶段保护我的应用程序。
我读过这篇关于从基本身份验证中排除一个网址的文章
但我想排除 2 个网址:
/API/*
/oauth/v2/令牌
因此,除了这两个公开的 url 之外,整个应用程序都将受到保护。否则我无法访问我的 api 路由。
我现在的 .htaccess 是:
# Protect the app with password
AuthUserFile /home/master/public_html/web/.htpasswd
AuthName "Protected"
AuthType Basic
Require valid-user
Run Code Online (Sandbox Code Playgroud)
所以我猜我应该需要某种排序或正则表达式:
SetEnvIf Request_URI ^/api/ noauth=1
Run Code Online (Sandbox Code Playgroud)
我怎样才能有像 OR 条件?