【问题标题】:Have sub directory not be password protected using Apache's .htaccess使用 Apache 的 .htaccess 使子目录不受密码保护
【发布时间】:2011-03-12 05:42:16
【问题描述】:

目前在我的服务器上,我的 web 目录的根目录中有一个 .htaccess 文件 -

AuthUserFile /path/to/root/www/.htpasswd
AuthType Basic
AuthName "Economic Complexity Observatory"
Require valid-user`

这很好用密码保护我的整个网站。唯一的问题是我有一个我不想受密码保护的子目录。有没有办法指定一个特定目录不受密码保护?

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    有一种方法只使用 .htaccess。我看到了这个答案elsewhere

    只需在不受密码保护的子目录中创建一个 .htaccess 文件,内容如下:

    Satisfy any
    

    就是这样。

    它对我有用。

    【讨论】:

    • 以某种方式为我工作。我仍然得到用户名和密码输入的身份验证弹出窗口......在某些浏览器上它可以正常工作。但对我来说,使用 firefox 和 windows 7 它并没有……知道为什么吗?
    【解决方案2】:

    如果您有权访问 httpd.conf,则可以使用以下内容(“目录”指令不能在 .htaccess 中使用):

    <Directory />
    AuthUserFile /path/to/root/www/.htpasswd
    AuthType Basic
    AuthName "Economic Complexity Observatory"
    Require valid-user
    </Directory>
    
    <Directory /path/to/unprotected/dir>
    Satisfy All
    </Directory>
    

    我不知道有一种方法可以用 htaccess 做到这一点,而无需在每个目录中放置一个单独的 .htaccess,不应该保护的目录除外。

    【讨论】:

    • 必须使用“Any”而不是“All”,即我的 site.conf 看起来像:&lt;Directory /path/to/unprotected/dir&gt; Options Indexes FollowSymLinks AllowOverride None Order Deny,Allow Allow from all Satisfy Any &lt;/Directory&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多