如何使Basic Auth排除重写的URL

问题描述 投票:0回答:3
问题是排除通过我的

mod_rewrite

文件中的
.htaccess

规则的URL。我的设置是,我所有的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>
....
我发现了与我的
Herey

here
相似的问题,但是答案只给了我我已经在尝试的东西。 我也想到了其他解决方案,但这将是最后的解决方案。我想看看是否有可能像我目前这样做的方式:

设置我的php代码中的基本验证 目前很麻烦

在我的

.htaccess
    文件中输入身份验证
    • 不想这样做,因为我只希望在3个服务器之一上进行身份验证。我知道我可以再使用一些
    • SetEnvIf HOST ...
    • ,但是我希望查看是否可以以这种方式修复它。
  • 规则:
      mod_rewrite
    • 	
    • 添加
  • ... RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php [L,QSA]

对于我来说,类似魅力的事情是:

Allow from env=REDIRECT_noauth
apache .htaccess authentication mod-rewrite .htpasswd
3个回答
21
投票

这对我有用:

<location />
        SetEnvIf Request_URI "/businesses/upload_logo" REDIRECT_noauth=1
        AuthType Basic
        AuthName "Restricted Files"
        AuthUserFile /etc/httpd/passwords/passwords
        Order Deny,Allow
        Satisfy any
        Deny from all
        Allow from env=REDIRECT_noauth
        Require user yournickname
</location>

2
投票

除非您的配置中的其他地方有冲突的指令,否则您应该使用的是您所提供的。 我已经做了类似的工作设置,只是我已经使用了文件系统路径而不是uri

我在这里添加它,希望您可能会发现它有用
SetEnvIf Host domain.com block_access

AuthUserFile /path/to/.htpasswd

AuthName 'Login'
AuthType Basic
Require valid-user

Order Allow,Deny
Allow from all
Deny from env=block_access

Satisfy Any

<If "%{THE_REQUEST} =~ m#^GET /api/always/available#">
    Allow from All
    Satisfy Any
</If>

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.