Skip to content
Dr. Thomas Jansen edited this page Dec 11, 2023 · 9 revisions

Preventing Git repository exposure in Apache

Global https.conf (recommended)

If you are using the Apache HTTP server, add the following DirectoryMatch directive to your global httpd.conf file:

Apache 2.4

<DirectoryMatch "/\.git">
    Require all denied
</DirectoryMatch>

Apache 2.2

<DirectoryMatch "/\.git">
    Deny from all
</DirectoryMatch>

Note

Don't forget to restart Apache after making the change, e.g. on Debian:

sudo systemctl restart apache2

Local .htaccess

If you are using the Apache HTTP server on a shared host, add the following directives to you local .htaccess file:

RewriteEngine On
RewriteRule ^\.git - [F]
Clone this wiki locally