Sep 09 2011

Password protect apache directory with htaccess

Protect web folder using Apache’s .htaccess method.

Create a new htaccess file in the folder you want to be protected. Name it .htaccess
Fill it with :

AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user xyz

The .htpasswd file would look like this:


If there are multiple users in .htpasswd file, the you must replace Require user xyz with require valid-user.
If you are using Apache2 make sure the following is included in the apache conf file for that folder :

AllowOverride AuthConfig

instead of

AllowOverride None

You can find here a password generator : http://www.addedbytes.com/lab/password-protect-a-directory-with-htaccess/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.