To set up password protect for specific pages or folder on your website is very easy with any cPanel hosting. This can be very useful when you need to limit access to a certain part of your site. See how to password protect any selected pages you like and access only authorized access your certain pages on your site.
How to Password Protect Pages in cPanel?
Log on your hosting control panel. Go to Security section, click Directory Password. This option will allow you to require a username and password to access a folder or website pages below it from the web.
You can select the folder you wish to protect by clicking on its name. If you want to open a folder, click on the icon before the folder name. In this test, our domain is test.betterhostreview.com, it is mapped to a folder named ‘test’ with a sub-directory ‘passwordprotect’ below it. We have put all website pages in this sub-directory ‘passwordprotect’, so any access request to those pages under this folder will require the authentication through username and password.
Click on the folder name to enable password protect on it. Then a page displays as below.
There are the sections basically: Security Settings and Create User. Let’s go to create a user with password first. Fill in your username and password twice, then click Add/modify Authorized User.
After that, you should find the created user listed in the Authorized Users list, see below screenshot. Go to create additional users if you like by repeating above steps.
Scroll up the screen to the Security Settings section. Tick Password protect this directory option, and name the protected directory, click Save when you are done.
Now you have create authorized users with passwords and you have enabled password protection on the selected folder with files and pages contained.
Visit the protected folder or a specific page in it from your web browser, such as http://test.betterhostreview.com/passwordprotect/ or http://test.betterhostreview.com/passwordprotect/page1.html, you will be prompted to login with username and password. You cann’t pass through the required authentication and your selected folder and all pages in it have been protected by password.
Password Protect Pages using .htaccess
If you are familiar with the code, you can actually setup password protection for any web pages or folders by manipulating the .htaccess file directly. Above instructions shows us how to use the cPanel built-in feature Directory Password. By using this feature, the cPanel has created two files to enable the password protect on your pages.
If you open the File Manager in cPanel, you wil find a special file password created automatically. You can find it from cPanel >> File Manager >> .htpasswds ….>>passwd. This file contains the user name and password which you can use to access the password protect pages or folders on your website.
The password info saved is not all. cPanel has activated the password protection on pages by creating an .htaccess file and inject a code in it. When your website visitor trying to browse the restricted pages, the .htaccess file will prompt them to log on with username and password. Once your visitor input the username and password, this fill will look up the saved password and username in the first file, only when they match can the visitor pass the authentication. You can find the .htaccess file in the same folder with your pages that you have setup the password protect.
Open this .htaccess file, you can find out the code which activates the password protection for your pages and folders. The code as below.
Website Page Password Protect Extra Tips
- The steps above should work on almost all Linux Apache servers or cPanel hosting service. These include Arvive, Bluehost, Inmotion Web hosting, Hostgator, Justhost and many more.
- If you have a WordPress site and want to set password protection for certain articles or posts, check out this guide: Protecting WordPress Posts and Pages with Password.
- Want to protect a whole folder of files? Follow the steps to protect site directories from cPanel?