If you have some special content that you want to hide from regular users or if you don’t want search engines to know about all the contents of your website, password protecting your webpages may sound like a good idea to you. Well, if you have a WordPress site, you can manually password protect the pages from your administrator account. However, to avoid trouble, you can do the same right from your hosting account, modifying the .htaccess file.
Things you need to do
- For adding password protection for your web pages, first of all, create a text file containing the username and password. Now, store it on your server.
- Create a file with the extension .htaccess and then add it in the folder which you want to password protect.
Creating the password protected file
The simple text file will contain your username and password; those two should be separated by a colon (‘:’). However, there is a catch. The password should be encrypted. You can easily do it through the numerous websites available online: 4WebHelp, Alterlinks, htmlite etc.
In any of these websites, you have to enter the username and password. Now, submit the form and you will get a string similar to this: fred:p29cmnwl4a0et (Where fred is the username).
Now, paste this string into a notepad and save it as .htpasswd. You should place this text file outside the web root folder of your website.
Creating and placing the htaccess file
Open a new file in your notepad and then save it as .htaccess. In the file, put the following code:
AuthName "My Secret Folder"
/full/path/to/.htpasswd is the location to the .htpasswd file that you uploaded earlier. If you are not sure about the full path, you should ask your hosting provider and they will provide you with the exact path.
The .htaccess file will password – protect all the sub-folders and files of the folder where it is placed. If you want to password protect a specific file, then you should write the following code in the .htaccess file:
AuthName "My Secret Page"
This will password – protect only the file .mypage.html.
The steps may seem a bit intimidating when starting out. But, just follow whatever is mentioned above and you should do fine. If you face any problem, please feel free to ask me questions through the comments feature available.