password protect a single file using .htaccess

感情迁移 提交于 2020-08-18 06:44:29

问题


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

    <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


回答1:


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


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>


来源:https://stackoverflow.com/questions/13570898/password-protect-a-single-file-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!