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
- Log into your cPanel admin dashboard.
- 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.
- Once you are in the right folder. Highlight the .htaccess file and click on the Edit icon found in the upper toolbar.
- 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
- 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>
- 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.
Before | After |
|
|
We value your feedback!
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.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!