密码使用.htaccess保护单个文件

时间:2022-09-16 22:57:04

I have tried to password protect a single file using .htaccess. But when accessing the file the browser just redirects to the home page of the website. I have my .htpasswd on my webroot. My .htaccess file is given below

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

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

I want to protect the file result.php. I have replaced username with my exact cpanel username. Someone please help

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

2 个解决方案

#1


3  

 <FilesMatch "results.php">
 AuthName "Member Only"
 AuthType Basic
 AuthUserFile /home/username/public_html/.htpasswd
 require valid-user
 </FilesMatch>
  • have to put a full absolute path of the password directory
  • 必须放置密码目录的完整绝对路径

#2


1  

Here is an example

这是一个例子

# 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>

#1


3  

 <FilesMatch "results.php">
 AuthName "Member Only"
 AuthType Basic
 AuthUserFile /home/username/public_html/.htpasswd
 require valid-user
 </FilesMatch>
  • have to put a full absolute path of the password directory
  • 必须放置密码目录的完整绝对路径

#2


1  

Here is an example

这是一个例子

# 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>