【问题标题】:htaccess restrict authentification but exception on filehtaccess 限制身份验证但文件异常
【发布时间】:2015-11-21 10:17:06
【问题描述】:

我看过其他一些相关的帖子,但没有找到任何解决方案。

我需要通过身份验证来限制文件夹,它可以工作。 但是在这个文件夹中,我需要保持一个对所有人开放的文件访问权限,我使用了这个但它不起作用:

AuthName "Admins Only"
AuthUserFile /home/dd/.htpasswd
AuthGroupFile /dev/null
AuthType basic
require user AuthorizedUser
Options -Indexes
<Files "admin-ajax.php">
   Allow from all
   Satisfy all
</Files>

对不起,我的英语不好,感谢您的帮助!

【问题讨论】:

    标签: apache .htaccess .htpasswd


    【解决方案1】:

    使用 SetEnv 和 Order 指令:

    #set variable if uri is "/admin-ajax.php"
    SetEnvIf Request_URI ^/folder/admin-ajax\.php noauth=1
    
    #auth 
    AuthName "Admins Only"
    AuthUserFile /home/dd/.htpasswd
    AuthGroupFile /dev/null
    AuthType basic
    require user AuthorizedUser
    
     #Here is where we allow/deny
    Order Deny,Allow
    Satisfy any
    Deny from all
    Require user AuthorizedUser
    Allow from env=noauth
    

    这将使您无需登录服务器即可访问您的 admin-ajax.php

    【讨论】:

    • 对不起,它不起作用。如果我尝试访问此文件,我仍然会出现登录窗口。我应该使用完整的服务器网址:SetEnvIf Request_URI ^/home/dd/admin-ajax\.php noauth=1 吗?
    • admin-ajax.php的完整url是什么?
    • 您的 admin-ajax.php 文件是否在根文件夹中?
    • 文件 admin-ajax.php 位于子文件夹中,而不是根文件夹中:/home/www/folder/admin-ajax.php。该网站的根文件夹是/home/www/。我更新了主帖中的网址,使其更易于理解^^。
    • 我编辑了我的答案,将 folder 替换为 SetenvIf 行中的 subfolder 的名称
    猜你喜欢
    • 1970-01-01
    • 2015-07-23
    • 2018-12-10
    • 2012-01-07
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多