Password Protect a Website or Sub-directory: Steps

Last Updated September 19, 2014
Est. Reading: 1 minute

Recently I was setting up a back-end admin page for a site and I wanted it to be only accessible by admins. So I came across an article by Chris Coyier on But the article was for advanced users. A newbie like me will end up getting errors. I ended up getting 500 Server error and after hours of Googling I was able to set it up properly. Follow the steps below and you will be able to password protect a website or sub-directory in no time.


Creating .htaccess and .htpasswd files

Visit to generate the contents for your .htaccess and .htpasswd files. It's a free online .htaccess Password Generator.

password protect website

  1. Enter usernames, one per line
  2. Enter passwords for the usernames on the left
  3. Enter filepath where you will be storing your .htpasswd (If you don't know the filepath, read the end of the article).
  4. Submit

After submitting you will get a page with your .htaccess and .htpasswd codes.

htacces password generator

Create 2 files .htaccess and .htpasswd in the file directory you want to protect and copy paste the codes from the above site to the respective file.

htaccess location for password protection

Finding the path of of the folder where you will be storing your password file (.htpasswd)

This is for people who don't know the full path of your site directory.

Visit and follow the instructions to find your full path of your site directory.

I have tried to keep the steps as simple as possible. If you run into some error, let me know through the comments and I will help you sort it out.

Written by Jijo Jose

Founder welovefilm & ShortoftheMonth. MBA student, gamer & blogger. Loves watching Animated & Sci-Fi Films.

© Viral Media Today 2024