htaccess – directories with password protection

  Web Hosting, htaccess

On our web hosting can be easily password-protected folder and all its contents, so that the visitor gets to it only after entering the correct username and password.

In the following example, we will protect by password subdirectory secret, So that what is available at URL http://yourdomain/secret/.

In the appropriate directory www/secret create a file .htaccess with the following content:

AuthUserFile /data/web/virtuals/2222/virtual/www/secret/.htpasswd
AuthGroupFile /dev/null
AuthName "Title of secret part of the site"
AuthType Basic
Require valid-user
Order deny,allow

In the file path .htpasswd you must replace the number 2222 by number of your webhosts (this number is part of your logins for FTP and databases).

Then you need to create a file .htpasswd, in which is stored a list of users with their passwords. There is one user per line – the line shall be indicated username, followed by a colon and the hashed password. To create content of file .htpasswd use htpasswd generator.

Example of .htpasswd file content:

karel:$apr1$5cK3b4YD$qVGM7CbNIrjTScxrv2TdQ/

After this is all done and when you accessing the URL address browser requests a username and password.

If after this setting appears error 500, make sure that you have in the file .htaccess is everything entered correctly, including correct absolute path to the file .htpasswd.

Děkujeme za zpětnou vazbu!