A Web Design Community curated by Chris Coyier

Code Snippets Gallery

Code Snippets > HTAccess > Password Protect Folder(s) Submit one!

Password Protect Folder(s)

Put in .htaccess file in the directory you are trying to protect:

AuthType Basic
AuthName "This Area is Password Protected"
AuthUserFile /full/path/to/.htpasswd
Require valid-user

Ideally, the .htpasswd file will be not in a public facing directory. Put this in there:

chriscoyier:$apr1$O/BJv...$vIHV9Q7ySPkw6Mv6Kd/ZE/

That is just a sample, you can create the code for your unique username and password here.

Note that all subdirectories of this directory will also be password protected by this same system.

2 Responses

  1. TeMc says:

    Yup, very good to mention that .htpasswd should NOT be in the same directory as the directory you’re trying to protect or any other location within something alike “public_html”.

    I usually put .htpasswd files in domain- or home-folders.

    eg:
    /home/myusername/domains/domain.com/
    or
    ~/var/home/


    TeMc

  2. I am really very thanks for this information

Leave a Comment

Remember:
  • Be nice.
  • Wrap multiline code in <pre> and <code> tags and escape it first (turn <'s into &lt;'s).
  • You may use regular HTML stuff like <a href="">, <em>, and <strong>
* This website may or may not contain any actual CSS or Tricks.