Difference between revisions of ".htaccess password protect directories"

From Imaginet FAQ
Jump to navigation Jump to search
(Created page with "This tutorial will explain how you can password protect a specific directory, so only authorized users can access that directory. There is an Online .htaccess Password Generat...")
 
Line 11: Line 11:
 
  AuthName "Restricted Area"  
 
  AuthName "Restricted Area"  
 
  AuthType Basic  
 
  AuthType Basic  
  AuthUserFile /var/www/vhosts/designyourwebsite.co.za/password/.htpasswd  
+
  AuthUserFile /var/www/vhosts/designyourwebsite.co.za/somedirectory/.htpasswd  
 
  AuthGroupFile /dev/null  
 
  AuthGroupFile /dev/null  
 
  require valid-user
 
  require valid-user

Revision as of 08:43, 5 November 2012

This tutorial will explain how you can password protect a specific directory, so only authorized users can access that directory. There is an Online .htaccess Password Generator that simplifies this which can be found on this website [htaccess Generator]

The instructions are quite clear, but remember that the path to where you store the .htpasswd file needs to be

/var/www/vhosts/yourdomainname.co.za/somedirectory/

Please fine the example that I did below.

Step 1: Insert the below code into your .htaccess file, and upload this file to the directory you wish to protect (or which the files you wish to protect is under): .htaccess:

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /var/www/vhosts/designyourwebsite.co.za/somedirectory/.htpasswd 
AuthGroupFile /dev/null 
require valid-user

Step 2: Save the below code into a file called .htpasswd, and upload this file to the location as specified in the "AuthUserFile" line above. It contains your username(s) and encrypted password(s). Important: .htpasswd should be put in a non public folder, such as directly above your public HTML folder, to prevent visitors from viewing this file in the browser. .htpasswd:

exampleuser:ipNgs4Ag1NdmA