password protect a single file using .htaccess

Shanker Krishnan picture Shanker Krishnan · Nov 26, 2012 · Viewed 11.2k times · Source

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

Answer

user7796852 picture user7796852 · Apr 1, 2017
 <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