How to Deny Access to Hidden Files and Directories

Last modified: January 18, 2025
You are here:
Estimated reading time: < 1 min

Hidden files and directories (those whose names begin with a dot, such as .htaccess, .htpasswd, .git, and .hg) should generally be secured, as they often contain sensitive configuration settings or version control data. Exposing these files could lead to potential security risks, so it’s important to block external access to them.

RewriteCond %{SCRIPT_FILENAME} -d [OR]

RewriteCond %{SCRIPT_FILENAME} -f

RewriteRule "(^|/)\." - [F]

Alternatively, you can simply trigger a ‘Not Found’ error, leaving the attacker without any useful information:

RedirectMatch 404 /\..*$
." - [F]
Was this article helpful?
Dislike 0
Views: 22

Braw Hosting Sales

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.

Scroll to Top