Password Protect Files And Folders
You can restrict access to certain files and directories on your website using htaccess.
First, you can password protect one specific file:
<Files private.php>
AuthType Basic
AuthName “Restricted”
AuthUserFile /home/path/.htpasswd
Require valid-user
</Files>
AuthType Basic
AuthName “Restricted”
AuthUserFile /home/path/.htpasswd
Require valid-user
</Files>
Next, you can password protect multiple files using FilesMatch:
<FilesMatch “^(private|protected|secure|index)*$”>
AuthType basic
AuthName “Restricted”
AuthUserFile /home/path/.htpasswd
Require valid-user
</FilesMatch>
AuthType basic
AuthName “Restricted”
AuthUserFile /home/path/.htpasswd
Require valid-user
</FilesMatch>
In the above example, any files which contain “private”, “protected”, “secure” or “index” will be password protected.
To password protect the entire directory, you would use this:
AuthType Basic
AuthName “Sorry, Restricted Area!”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
AuthName “Sorry, Restricted Area!”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
If you are on your site all day and don’t want to be prompted for a password all the time, you can grant automatic access to any user by specific IP address:
AuthType Basic
AuthName “Sorry, Restricted Area!”
AuthUserFile /home/path/.htpasswd
Require valid-user
Allow from 123.45.67.890
Satisfy Any
AuthName “Sorry, Restricted Area!”
AuthUserFile /home/path/.htpasswd
Require valid-user
Allow from 123.45.67.890
Satisfy Any
Just replace the above example with your own IP address.




