If you don't know the username and password to enter, then you can't access the page or site - it's "password protected". It's sometimes handy to be able to password protect your pages like this - for example:
- You're building a new site, but you only want yourself (and maybe a select few) to be able to view the work-in-progress.
- You have an area of your site that you never want the general public to have access to - for example, your web stats or private pages.
- You have some paid (subscription) content on your site that only subscribers should be able to access.
- Apache lets you password protect individual files, folders, or your entire site fairly easily. Read on to find out how it's done.
- Create a special file called .htaccess in the folder you want to protect.
ErrorDocument 401 "Unauthorized"2. Creating the password file Called .htpasswd
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/*/public_html/directory/.htpasswd
require user myusername_same_as_.htpasswd_file
The first step is to create a simple text file that will store your username and password, separated by a colon (:). The small catch is that the password must be encrypted. Luckily, there are many free web-based utilities that will encrypt the password for you. Try one of these:
myusername_same_as_.htaccess_file:$apr1$TSQAiMQm$MIJ.m3qpJ3mnY6NXdzppz.