Skip to content

Instantly share code, notes, and snippets.

@rxnlabs
Created July 25, 2023 16:15
Show Gist options
  • Save rxnlabs/62d34cc21074a8f0abb381a228627e27 to your computer and use it in GitHub Desktop.
Save rxnlabs/62d34cc21074a8f0abb381a228627e27 to your computer and use it in GitHub Desktop.
Apache - .htaccess prevent Git repos .git/ folder from being viewable
# BEGIN Cornershop
# VCS lockdown
# Deny access to version control content
# Will not work if both Alias & Rewrite modules are disabled
# To verify with git content, check these two URLs:
# 1. /.git/HEAD
# 2. /.gitignore
<IfModule mod_alias.c>
# Deny access to VCS content using Alias Module
RedirectMatch 404 ^(.*/)?\.(git|svn|hg|bzr)+
</IfModule>
<IfModule !mod_alias.c>
<IfModule mod_rewrite.c>
# If Alias Module is not available but Rewrite Module is,
# use Rewrite Module to deny access to VCS content
RewriteEngine On
RewriteBase /
RewriteRule ^(.*/)?\.(git|svn|hg|bzr)+ - [R=404,L]
</IfModule>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment