You are here

28 April 2014
Protect site with password using htaccess. The htpasswd file is just a text file that includes usernames and password hashes. You can generate those by using online tools for generating htaccess passwords. First bit of code is simplest htaccess password protection code that needs to be copied to your .htaccess file. The second one enables you to password protect defined directories using regular expressions.
Source code viewer
  1. # Global password protection
  2. AuthUserFile /full/directory/to/htdocs/.htpasswd
  3. AuthName "Password Protected"
  4. AuthType Basic
  5.  
  6. Order Deny,Allow
  7. Deny from all
  8. Satisfy any
  9. Require valid-user
Programming Language: Apache configuration
Source code viewer
  1. # Password only on ^/bank/notification
  2. SetEnvIfNoCase Request_URI ^/bank/notification require_auth=true
  3. AuthUserFile /full/directory/to/htdocs/.htpasswd
  4. AuthName "Password Protected"
  5. AuthType Basic
  6.  
  7. Order Deny,Allow
  8. Deny from all
  9. Satisfy any
  10. Require valid-user
  11. Allow from env=!require_auth
Programming Language: Apache configuration