How to restrict access to your website with .htaccess

If you don't have a CMS (Content Management System) on your website that controls access to parts of your site, the quickest and easiest way to keep an area of your site away from prying eyes is to use .htaccess

A .htaccess file is a small text file that has many uses, and is placed in directories on your webserver. Often, FTP clients have trouble transferring these files, so cPanel has a convenient function for adding password protection to your site with .htaccess - here's how.

Step 1 - Select "Password Protect Directories" in cPanel

Password Protected DirectoriesLog in to cPanel, and select "Password Protected Directories" from the options. In newer cPanel versions it's located in the "Security" section.

You may see the screen below, asking where you want to start when looking for which directory you want to protect. Choose the top option, "Web Root". This starts at public_html/ aka www.yourdomain.com/

File Manager Directory Selection

Step 2 - Choose the directory to protect

If you want to prevent anyone from accessing anything on your site (if your website is in test mode, for example), choose "/" - which is the root of your website. Anyone trying to access something at www.yourdomain.com will be asked for a password. Otherwise, use the folders to navigate to the directory containing your private files.

Select Folder to Protect

Step 3 - Choose a "login message"

cPanel calls this "Name the protected directory" but basically it's a little message that will be shown along with the Username/Password box, when people try to access the directory in question. This could be "Keep Out!" or simply "Please enter your username and password"

Login Message

Step 4 - Set username and password information

Further down the page, you'll see a place to enter a username and password for the directory. Note that it is possible to have more than one username and password that you can distribute to your users. This is useful as their username will show up in your access logs and statistics, should you wish to track it.

Add User

Click "Add/Modify Authorized User", and you're all set! Be sure to test it!

By:Henry | Filed under:Control Panels, Server Security | Tags: , , ,

What Next?

Latest HostHow Activity

One Response to “How to restrict access to your website with .htaccess”

[…] How to restrict access to your website with .htaccess […]

Leave a Reply