Tuesday, November 15, 2011

How to protect a web page with htaccess with a password

  1. Create a .htpasswd file:
    $ htpasswd -c .htpasswd <username>
    password: 
    
  2. Create or add these lines to .htaccess file:
    • To protect a directory:
      AuthUserFile /full/path/to/.htpasswd
      AuthType Basic
      AuthName "Protected Folder"
      Require valid-user
      
    • To protect a file:
      AuthUserFile /full/path/to/.htpasswd
      AuthType Basic
      AuthName "Protected Page"
      
      <Files "protected_page.html">
        Require valid-user
      </Files>
      

No comments:

Post a Comment