Cantech Knowledge Base

Your Go-To Hosting Resource

How to Deny Access to .htaccess File using cPanel?

The .htaccess files are important hidden files of your hosting and we recommend securing them .htaccess rules. One way to do this is to deny access to the .htaccess file via cPanel file manager.

Steps to Deny Access to .htaccess File

  1. Log in to your cPanel Account.
  2. Open the File Manager and edit the .htaccess file.
  3. Add this code at the end of the file:
# Deny access to hidden files - files that start with a dot (.)
<FilesMatch "^\.">
Order allow,deny
Deny from all
  1. Choose Save Changes and Close the file.

code file

Conclusion

If you own a VPS or dedicated server, you can save the .htaccess/hidden files on all the sites on it. You may have to edit the /home/.htaccess file and enter the code there.

November 4, 2026