Creating the password file using htpasswd
htpasswd -c .htpasswd fred
Protecting a folder
To password protect a folder on your site, you need to put the following code in your.htaccess file:
AuthName "My Secret Folder"
/full/path/to/.htpasswd should be the full path to the .htpasswd file that you uploaded earlier. The full path is the path to the file from the Web server’s volume root – for example, /home/username/.htpasswd or C:wwwrootusername.htpasswd. (If you’re not sure of the full path to your site or home directory, ask your Web hosting company for this info.)
The above .htaccess file will password protect all files in the folder that it is placed in, and all sub-folders under that folder too. So if you wanted to password protect your entire site, you would place the .htaccess file in your Web root folder.
Protecting a file
To password protect just a single file in a folder, use the following .htaccess file:
AuthName "My Secret Page"
This will password protect just the mypage.html file in the folder where you put the.htaccess file.