---
title: "Selective Password Protection | Netlify"
description: "Realize the speed, agility and performance of a scalable, composable web architecture with Netlify. Explore the composable web platform now!"
source: "https://www.netlify.com/blog/2017/04/07/selective-password-protection/"
last_updated: "2026-08-30T01:27:54.000Z"
---
We recognize that one size does not fit all. Sometimes you need to password protect some or all of your deploy previews so that curious minds don’t get the jump on your new product or announcement. Let’s walk through a way to protect specific deploys on any paid account (password protection is a paid feature).

This example will apply to all deploy previews for branches other than your main branch. So, we’ll still build and deploy the main branch and PR’s against it as usual with this configuration. If you need to limit it to just some branches but want others unprotected, you should be able to extrapolate this example but if that is problematic [please contact support](/support/) and we can advise further.

You will almost certainly want to adapt this to tooling that you otherwise use (unless you, like me, are a bit old-school and still use make and Makefiles :) )

In this setup, you’ll use deploy contexts to perform different behavior on selected deploys, as documented here:

[https://www.netlify.com/blog/2016/08/30/introducing-deploy-contexts-in-netlify/](https://www.netlify.com/blog/2016/08/30/introducing-deploy-contexts-in-netlify/)

What we’re doing: creating an `_headers` file (see [https://docs.netlify.com/routing/headers/](https://docs.netlify.com/routing/headers/) for more info) that we will use only for deploy previews on your specified branches. This will be copied into place for previews (that is, anything not a commit or PR on master), and thereby cause Basic HTTP Authentication to be enforced for the entire site in those previews.

Note that there are 3 different files here. The `Makefile` directs the build process to do different things depending on which target is selected; the `netlify.toml` will select the target automatically based on the deploy type (master or not), and the `_headers` (copied into place from someplace it won’t be used accidentally on master!) contains the authentication forcing function.

Makefile:

```
​production:    middleman contentful && middleman build​deploy_preview:    middleman contentful && middleman build && cp netlify_headers _site/_headers
```

netlify.toml:

```
[context.production]  command = "make production"[context.branch-deploy]  command = "make deploy_preview"​
```

netlify\_headers:

```
/*        Basic-Auth: login:password
```

### Share

-   [X (fka Twitter)](https://twitter.com/intent/tweet?text=Selective Password Protection&url=https://www.netlify.com/blog/2017/04/07/selective-password-protection/)
-   [LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.netlify.com%2Fblog%2F2017%2F04%2F07%2Fselective-password-protection%2F)
-   [Facebook](https://www.facebook.com/sharer.php?u=https://www.netlify.com/blog/2017/04/07/selective-password-protection/)
-   [Bluesky](https://bsky.app/intent/compose?text=Selective Password Protection+https://www.netlify.com/blog/2017/04/07/selective-password-protection/)

* * *

### Tags

-   [Deploys](/blog/tags/deploys/)

## Keep reading

![](/_astro/3f45eb6eda4ea8814be310e3df4a7883a5bd9ba0-1200x675_ZcBDUS.webp)

Guides & Tutorials May 15, 2026

[

### How to build a real-time AI chatbot in minutes with Netlify Agent Runners (no backend)

](/blog/how-to-build-a-real-time-ai-chatbot-in-minutes-with-netlify-agent-runners-no-backend)

-   ![Profile picture of Nahrin Jalal](/_astro/f0e7c8f227a03fe58340c99ef5439d5a896c0733-272x272_Z23kDpD.webp)
    
    Nahrin Jalal
    

![](/_astro/8fe9e8a23f944c9912003233d99a2df7fee637cf-1600x900_Z1gMhmf.webp)

Guides & Tutorials May 15, 2026

[

### Tracking AI search traffic: how to use Netlify Log Drains to maximize AEO

](/blog/tracking-ai-search-traffic)

-   ![Profile picture of Nahrin Jalal](/_astro/f0e7c8f227a03fe58340c99ef5439d5a896c0733-272x272_Z23kDpD.webp)
    
    Nahrin Jalal
    

## Recent posts

News & Announcements August 25, 2026

[

### Compete in OpenAI’s WebMCP Challenge with Netlify

](/blog/compete-openai-webmcp-challenge)

-   ![Profile picture of Karthik Puvvada](/_astro/e5524d3c315ad5114e1d5300d8991bfe902916fe-192x192_Z1w18MB.webp)
    
    Karthik Puvvada
    

News & Announcements August 19, 2026

[

### New clarifying questions in Agent Runners

](/blog/new-clarifying-questions-in-agent-runners)

-   ![Profile picture of Taylor Barnett-Torabi](/_astro/cf4624da8c1286738397b6fecb53bad504df140b-400x400_ZsvK0s.webp)
    
    Taylor Barnett-Torabi
    

Opinions & Insights August 14, 2026

[

### The full power of Git, without the friction: A conversation with Netlify CTO Dana Lawson

](/blog/netlify-source-with-netlify-cto-dana-lawson)

-   ![Profile picture of Dana Lawson](/_astro/856bf146d0c05c9dc25d45b59f7eac955fbbd644-512x512_1n84rs.webp)
    
    Dana Lawson
    

![](/_astro/3f255b372fa958df35802666ee33b4609b2d71bd-1200x1586_1VtE2D.webp)

### How do the best dev and marketing teams work together?

[Access the report](https://www.netlify.com/reports/2024-leadership-trend-report/access/)