Friday 6 November 2015

Disable mod_rewrite for subdirectory OR Set Apache Password Protected Directories With .htaccess File OR API Protected


If you don't know the username and password to enter, then you can't access the page or site - it's "password protected". It's sometimes handy to be able to password protect your pages like this - for example:


  1. You're building a new site, but you only want yourself (and maybe a select few) to be able to view the work-in-progress.
  2. You have an area of your site that you never want the general public to have access to - for example, your web stats or private pages.
  3. You have some paid (subscription) content on your site that only subscribers should be able to access.
  4. Apache lets you password protect individual files, folders, or your entire site fairly easily. Read on to find out how it's done.


  1. Create a special file called .htaccess in the folder you want to protect.
ErrorDocument 401 "Unauthorized"
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/*/public_html/directory/.htpasswd
require user myusername_same_as_.htpasswd_file
     2. Creating the password file Called .htpasswd
The first step is to create a simple text file that will store your username and password, separated by a colon (:). The small catch is that the password must be encrypted. Luckily, there are many free web-based utilities that will encrypt the password for you. Try one of these:
myusername_same_as_.htaccess_file:$apr1$TSQAiMQm$MIJ.m3qpJ3mnY6NXdzppz. 

No comments:

Post a Comment