Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

How to Secure .git repo repository files and directory web inaccessible

Many times, people use git repository to host website in productions by clone-push-pull but it has one drawbacks, it appears the .git directory is accessible via the web. How we can prevent this? Here there are 2 ways which are recommended given below;

  • One redirects to a 404 aka to issue a 404 (w/ mod_rewrite):
  • Redirect it to the domain root

Code Verified in June 2026

To be done in .htaccess in the website main directory


# Safely block all access to .git and related files
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule (^|/).git(/|$) - [F,L]
  RewriteRule (^|/).gitignore$ - [F,L]
  RewriteRule (^|/).gitmodules$ - [F,L]
</IfModule>Code language: HTML, XML (xml)

Summary Table

OptionSecuritySite works?SEO SafeRecommended?
Block Only (.git etc.)โœ… Strongโœ… Yesโœ… Yesโœ… Yes
Redirect EverythingโŒ BadโŒ NoโŒ NoโŒ No

<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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*/)?.git+ - [R=404,L]
# Redirect all traffic to the home page
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^ / [R=301,L]
</IfModule>

# Second line of defense (if no mod_rewrite)
RedirectMatch 404 ^(.*/)?.git+

# Redirect all traffic to the home page (if no mod_rewrite)
RedirectMatch 301 ^(.*)$ /
Code language: PHP (php)

How to download .git repo from public website?

$ wget --mirror -I .git https://www.domain.com/.git/ --no-check-certificate
$ wget --mirror -I .git https://www.domain.com/.git/Code language: JavaScript (javascript)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

E-commerce Fraud is Rising Sharply: How to Balance Security with Customer Experience

There has been a huge spike in e-commerce fraud in recent years, with cybercriminals targeting business sites to harvest customersโ€™ financial data and commit account takeover, loyalty…

Read More

Compare SAST, DAST and RASP & its Tools for DevSecOps

Static Application Security Testing (SAST) Dynamic Application Security Testing (DAST) Runtime application self-protection (RASP) Comparison of SAST, DAST, and RASP in DevSecOps Feature SAST (Static Application Security…

Read More

What is DevSecOps?

DevSecOps is an extension of the DevOps philosophy that integrates security practices into the entire software development lifecycle. It aims to ensure that security considerations are not…

Read More

Difference between DevSecOps vs. SecOps

Are you confused about the difference between DevSecOps and SecOps? Do you wonder if they are just different names for the same thing? Well, wonder no more!…

Read More

DevOps Trainer in Netherlands, Amsterdam

Getting highly skilled DevOps Trainer in this world is getting little hectic. Also if you are in Netherlands, Amsterdam and need highly skilled Trainers than this blog…

Read More

DevSecOps Trainer in Netherland, Amsterdam

DevSecOps engineersย choose and deploy the appropriate automated application security testing tools. It is their responsibility to make users aware of how to make the most of application…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
RustyNox
RustyNox
2 years ago

But why not deploy .git directory at all, then you can also skip ssh auth on production nightmare, etc.
main.yml

name: Deploy Source Files

on:
 push:
  branches:
   - main

jobs:
 deploy:
  runs-on: ubuntu-latest

  steps:
   - name: Checkout Repository
    uses: actions/checkout@v2

   - name: Copy Source Files
    run: |
     rsync -av --exclude='.git' --exclude='.github' ${{ github.workspace }}/ /path/to/production/server/

1
0
Would love your thoughts, please comment.x
()
x