【问题标题】:password protect a single file using .htaccess使用 .htaccess 密码保护单个文件
【发布时间】:2012-11-14 06:53:08
【问题描述】:

我尝试使用 .htaccess 对单个文件进行密码保护。但是在访问文件时,浏览器只会重定向到网站的主页。我的 .htpasswd 在我的 webroot 上。我的 .htaccess 文件如下所示

    <FilesMatch "result.php">
    AuthName "Member Only"
    AuthType Basic
    AuthUserFile /home/username/.htpasswd
    require valid-user
    </FilesMatch>

我想保护文件result.php。我已将用户名替换为我的确切 cpanel 用户名。有人请帮忙

【问题讨论】:

  • 你没有其他规则吗?

标签: .htaccess passwords cpanel .htpasswd


【解决方案1】:
 <FilesMatch "results.php">
 AuthName "Member Only"
 AuthType Basic
 AuthUserFile /home/username/public_html/.htpasswd
 require valid-user
 </FilesMatch>
  • 必须放密码目录的完整绝对路径

【讨论】:

    【解决方案2】:

    这是一个例子

    # password protect single file
    <IfModule mod_auth.c>
     <Files "protected.html">
      AuthName "Username and password required"
      AuthUserFile /home/path/.htpasswd
      Require valid-user
      AuthType Basic
     </Files>
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多