Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Using .htaccess to Password Protect Directories

Using .htaccess to Password Protect Directories

0

.htaccess provides a easy way of password protecting directories on your website, requiring users to enter a username and password in order to gain access. The process involves creating two files on your server – one for protecting the directory, and one for storing the usernames and passwords.

First, create a .htaccess file in the directory you want to protect. In the file, you need to enter the following:

AuthUserFile /path/to/.htpasswd
AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic

require valid-user

Next, create the .htpasswd file on your server. This can be at a location not accessible via your site’s host name (e.g. outside of public_html or www folders) or within the directory you want to password protect.

In this file, you can enter the usernames / passwords allowed to access the protected directory, like so:

user1:$apr1$PdOCG6JI$L6nINuh8L2.A5CM6q0H9A/
user2:$apr1$XEvewxg7$dtPPm8vvhxwW5Zo9hudIY1

The above two lines translates into two users, user1 and user2. Each user should be on a separate line. The passwords are as follows: pass1 and pass2, respectively. You can generate your own username and password using this handy website. For the above two examples, I used the MD5 algorithm to encrypt the passwords.

Apache, Security

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

PSN Profile

Tags

Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache API Application Backup Bug Command Line Cordova Example Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Geolocation Google Nexus 5 Google Nexus One Hacking HTML5 Image Manipulation iOS iPhone JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2022 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy