Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Last active December 17, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shrwnsan/5692615 to your computer and use it in GitHub Desktop.
Save shrwnsan/5692615 to your computer and use it in GitHub Desktop.
Make .git files and directory web inaccessible. There's two solutions below for your preference. One redirects to a 404, and the other to domain root. I use a 404. (Based on my Stack Overflow post @ http://j.mp/17fb164)
# Make .git files and directory web inaccessible
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*/)?\.git+ - [R=404,L]
</IfModule>
# Second line of defense (if no mod_rewrite)
RedirectMatch 404 ^(.*/)?\.git+
# Make .git files and directory web inaccessible
# Redirect it to the domain root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^(.*/)?\.git/" http://%{HTTP_HOST}/? [L]
</IfModule>
# Second line of defense (if no mod_rewrite)
RedirectMatch 404 ^(.*/)?\.git+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment