Password Protect Pages

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?

directory password protect 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.

select folder to protect

Click on the folder name to enable password protect on it. Then a page displays as below.

password protect settings main interface

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.

create authorized user for password protection
authorized users created


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.

enable password protect on your web pages and folders


Now you have create authorized users with passwords and you have enabled password protection on the selected folder with files and pages contained.

page access password protected with authentication required


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.

page access authorized username and password saved

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.

htaccess file 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.

htaccess code to activate page password protect

Website Page Password Protect Extra Tips

One comment

Leave a Reply