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...")
 
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
  /var/www/vhosts/yourdomainname.co.za/somedirectory/
 
  /var/www/vhosts/yourdomainname.co.za/somedirectory/
  
Please fine the example that I did below.
+
Please find 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):
+
Step 1: Insert the below code into your .htaccess file, and upload this file to the directory you wish to protect (or the directory which the files you wish to protect is under):
 
.htaccess:
 
.htaccess:
 
  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

Latest revision as of 16:05, 13 December 2021

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 find 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 the directory 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