Skip to content

Knowledgebase

Protecting .htaccess and configuration files from public downloads

security-ssl

A public request for .htaccess should not return the file contents. This file can reveal rewrite paths or access rules, and nearby configuration files may contain more sensitive information. Most Apache hosting already denies access to its .ht files, but you should verify the behavior after a migration or server change.

These instructions apply where the web server supports Apache-compatible .htaccess rules. Native NGINX does not read this file. A CDN or reverse proxy can also affect the request seen by the origin server. Keep File Manager or SFTP available so you can restore the previous file if a rule prevents browser access.

01 Check the current protection

  1. Request https://example.com/.htaccess without signing in. An access-denied or not-found response is appropriate; the contents should never be displayed or downloaded.
  2. If the file is exposed, contact support and review other public configuration files immediately. Keep a copy of the current rules before making changes.
  3. Where Apache 2.4-compatible per-directory authorization is supported, a narrowly scoped example is:
Code or configuration example
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

This example targets names beginning with .ht. It does not deny the whole website. Placing an unscoped Require all denied in the website root can block all visitors. Preserve existing server and application protection rules rather than replacing the complete configuration.

02 Verify access and inspect related risks

  1. Retest the protected URL and several normal pages. Confirm images, sign-in and expected downloads still work.
  2. Look for stray files such as editor backups, old configuration copies and SQL dumps. Move sensitive material outside the document root instead of relying on one filename pattern.
  3. Check that your deployment process preserves these rules. A rebuild that recreates .htaccess may remove a manually added section unless you maintain it in the deployment configuration.

Can a broad hidden-file rule break certificate validation?

Yes. A broad rule denying every dot-prefixed path can block legitimate validation paths unless the necessary exceptions are planned. Certificate validation and other standards can use /.well-known/. The example above targets .ht names only. On native NGINX, ask the server administrator to apply equivalent protection in the server configuration because .htaccess is ignored.

Was this answer helpful?

Need a little more help?

Our support team can help you find the next step.

Contact support