Protect web pages with username/password
Written on September 29, 2008 – 6:59 pm | by Rene
If there some web pages you want to protect with username/password, all you have to do is to create a file called .htaccess under the directory to protect with the following lines:
- AuthUserFile /path/to/htpasswd/.htpasswd
- AuthGroupFile /dev/null
- AuthName "Restricted Directory"
- AuthType Basic
- <Limit GET POST>
- require valid-user
- </Limit>
Replace /path/to/htpasswd/ with the .htpasswd path.
Replace Restricted Directory with the text you want as title of the prompt window.
Then you have to create the .htpasswd file using the following command:
htpasswd -c .htpasswd user_name
Execute it under the directory to protect or add the full path to .httpasswd and replace user_name by the username you want to use, you will be asked to enter the password and the file will be created.
Notes: This instruction are for linux/unix systems using apache web server, the dot means hidden files on linux.