Jump to content

Password Protection


Recommended Posts

For all of those who are familiar with .htaccess. Here's a way to protect ALL files on your site that begin with 'private'. Add the code below to your root directory's .htaccess file.

 

AuthType Basic
AuthName "Restricted Access"
AuthUserFile "/home/user/.htpasswds/public_html/passwd"

<Files ~ "^(private).*$">
require valid-user
</Files>

# protect another file called info.php

<Files "info.php">
require valid-user
</Files>

 

Here's a way to protect multible files:

 

<FilesMatch "^(exec|env|private|phpinfo).*$">
AuthName "Restricted Access"
AuthType basic
AuthUserFile "/home/user/.htpasswds/public_html/passwd"
Require valid-user
</FilesMatch>

 

The easiest way to set this up is to use the cpanel option to protect your public_html folder for password protection and then go back and edit the code to what I posted so all of your public_html folder doesn't reqire a password.

 

Cheers,

Byron

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...