Websites contain many different files within different folders. Outsiders may try to access these folder, or directories, looking for information such as configuration settings from different files. That is why you have the ability to block access to entire directories via your .htaccess file. However, you may need to give public access to one or more files and, due to the website or program structure, not be able to move the file to an unrestricted directory.

Again, with the help of the .htaccess file, you can allow access to specific files. This article will discuss and demonstrate how to allow public access to a specific file or files that are in a password protected directory using .htaccess file modification.

How to allow access to a file in a restricted directory

  1. Log into your cPanel admin dashboard.
  2. Using the cPanel File Manager tool, locate and enter the password protected directory you want to work with. Be sure you also enable the ability to see hidden files since you will be working with the .htaccess file.
  3. Once you are in the right folder. Highlight the .htaccess file and click on the Edit icon found in the upper toolbar.
  4. Now that you are in the editor, you will need to locate the security code for this directory. It should look similar to the code below.
    AuthType Basic
    AuthName "Restriction Test"
    AuthUserFile "/home/username/.htpasswds/public_html/test/passwd"
    require valid-user
  5. Once you find the code, you will want to add the new code below to tell the server to allow access to your desired file. The code below demonstrates code that allows access to a file named test.php. Note the \ before the . and the $ at the end of the filename. Ensure you do that for your filename as well. This helps ensure that only that exact filename can be accessed. You may repeat this as needed for each file you want to allow access to within the directory.
    <FilesMatch "test\.php$">
    Satisfy Any
    Allow from all
    </FilesMatch>
  6. After adding the access code, click the Save Changes button in the upper right corner to save them. Below is a shot of my attempt to access the test.php file before and after adding the code to my .htaccess file.
    BeforeAfter
    before access code inserted afte access code inserted
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!

Did you find this article helpful?

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.

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!
Need More Help?

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

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

Not a Customer?

Get web hosting from a company that is here to help.
}