Make .git directory web inaccessible

后端 未结 9 1685
耶瑟儿~
耶瑟儿~ 2020-11-30 17:22

I have a website that I use github (closed source) to track changes and update site. The only problem is, it appears the .git directory is accessible via the web. How can I

相关标签:
9条回答
  • mod_rewrite will give you the desired affect:

    RewriteEngine on
    RewriteRule .*\.git/.* - [F]
    
    0 讨论(0)
  • 2020-11-30 18:14

    Put this in an .htaccess file at the root of your web server:

    RedirectMatch 404 /\.git
    

    This solution is robust and secure: it

    • works for all .git directories in your site, even if there are more than one,
    • also hides other Git files like .gitignore and .gitmodules
    • works even for newly-added .git directories, and
    • doesn't even give away the fact that the directories exist.
    0 讨论(0)
  • 2020-11-30 18:14

    I didn't want to muck around in the .git directory and wasn't able to get Bennett's solution to work on Apache 2.2, but adding the following to my <VirtualHost> configuration worked:

    RewriteRule ^.*\.git.* - [R=404]
    
    0 讨论(0)
提交回复
热议问题