Allow public access to a file in a protected directory using .htaccess Print

  • public access, protected directory, .htaccess
  • 0

If you've protected a directory using password protection in cPanel (via .htaccess), but want to make one specific file (like example.pdf) publicly accessible, follow these steps:

Step-by-Step Instructions:

 

Step 1: Log in to cPanel

  • Go to yourdomain.com/cpanel (replace "yourdomain.com" with your actual domain)
  • Enter your cPanel username and password

Step 2: Locate the Protected Directory

  • Inside cPanel, go to “Files” > “File Manager.”
  • Navigate to the directory that is password-protected. (This would have an .htaccess file and possibly an .htpasswd file linked to it.)

Step 3: Edit the .htaccess File

  • Inside the protected folder, right-click the .htaccess file and choose Edit. If you don’t see the file, click Settings in the top-right corner and enable “Show Hidden Files (dotfiles)”.
  • Scroll to the bottom of the file and add the following lines (or modify as needed):

----------

<Files "example.pdf">
Satisfy Any
Order allow,deny
Allow from all
</Files>

----------

Replace example.pdf with the exact name of the file you want to make publicly accessible.

Step 4: Save the File

Click Save Changes and Close the editor.

Step 5: Test the File

  • Open a new private/incognito browser window.
  • Visit https://yourdomain.com/protected-folder/example.pdf. The file should open or download without requiring a login, even though the rest of the folder is protected.

Notes:

  • The rest of the directory will remain protected as long as the rest of the .htaccess file is unchanged.
  • Make sure the file has correct read permissions (usually 644).

Was this answer helpful?

« Back