首页 文章

如何从子目录中删除.htaccess密码保护

提问于
浏览
87

我有密码保护我的整个网站使用.htaccess,但我想公开其中一个子目录,以便无需密码即可查看 .

How can I disable htaccess password protection for a sub directory? Specifically what is the .htaccess syntax.

这是我的.htaccess文件放在我的ftp的根目录中

AuthName "Site Administratrion"
AuthUserFile /dir/.htpasswd
AuthGroupFile /dev/null

AuthName secure
AuthType Basic
require user username1
order allow,deny
allow from all

5 回答

  • 1

    如果您想阻止任何特定的直接来自htaccess身份验证,那么您可以在顶部的htaccess文件中使用以下代码 .

    AuthType Basic AuthName "Enter Pass" AuthUserFile /home/public_html/.htpasswd /*PATH TO YOUR .htpasswd FILE*/ Require valid-user SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" allow Order allow,deny Allow from env=allow

    另外如果要阻止多个目录,请添加

    SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" allow

    尽可能多的目录,你想从htaccess预防中删除 .

  • 137

    您需要在所需目录中创建一个新的 .htaccess 文件,并在其中包含 Satisfy any 指令,如下所示:

    # allows any user to see this directory
    Satisfy Any
    

    请注意Apache 2.4中的语法更改,这应该具有相同的效果

    Require all granted
    
  • 8

    添加到RageZ的答案,我在服务器指令中使用了这个:

    <Directory /var/www/protected/>
         AuthType Basic
         AuthName "Production"
         AuthUserFile /path/to/.htpasswd
         Require valid-user
    </Directory>
    
    <Directory /var/www/protected/unprotected>
         Satisfy Any
    </Directory>
    

    真棒 . 谢谢RageZ!

  • 0

    只需使用以下指令在所需的子目录中创建一个新的 .htaccess

    Allow from all

    您只能使用以下内容限制您的IP:

    Allow from x.x.x.x

    见:http://httpd.apache.org/docs/current/mod/mod_access_compat.html

  • 33

    您需要将另一个.htaccess文件添加到覆盖身份验证的子目录中 . .htaccess向上级联,即它将在当前文件夹中查找,然后上升到某个级别,依此类推 .

相关问题