Within your website structure, there are many times when you may want to protect directories from outside access. This prevents any user from accessing a subdirectory of your site, and its files, without a username and password. There may be a time, however, when you want to allow access to a single file within a password directory and it is not feasible to move the file to an unprotected directory or folder. The instructions below will guide you in how to allow access to a single file in a password protected directory using your .htaccess file.
 

How to allow access to a file in a protected directory

 
  1. Log into your cPanel dashboard.
  2. Access the File Manager and navigate to the password protected folder. Make sure you enable the ability to show hidden files.
  3. Within the password protected folder will be an .htaccess file that contains the security code to activate the password popup. Highlight the .htaccess file and click on the Edit icon from the toolbar across the top of the page.
  4. Once inside the editor, you will see the security code. It will appear similar to the example below. Our example directory was test, so attempting to access inmotiontesting.com/test resulted in a popup box asking for username and password.
    AuthName "test-protect"
    AuthUserFile "/home/userna5/.htpasswds/public_html/test/passwd"
    AuthType Basic
    require valid-user
  5. You will need to add the following code for each file you want to allow access to after the code above. In this example, we are allowing access to a file named test.php. Note the \ before the . in the filename and the $ at the end. You will want to do this for your file name as well to ensure access is given to that exact file.
    <FilesMatch "test\.php$">
    Satisfy Any
    Allow from all
    </FilesMatch>
  6. Click on the Save Changes button in the upper right corner to finalize and activate the code. Now you will be able to access the specific file named test.php but no other files within that directory.
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 200901

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!