---
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-07-14T07:38:41.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 July 13, 2026

[

### Netlify inside of Claude Design

](/blog/netlify-inside-of-claude-design)

-   ![Profile picture of Sean Roberts](/_astro/bbf2243f8171dbddd80ab2103622106cef84d125-512x512_Z1d2LKE.webp)
    
    Sean Roberts
    

News & Announcements June 25, 2026

[

### Netlify Functions, designed for Agent Experience

](/blog/netlify-functions-designed-for-agent-experience)

-   ![Profile picture of Eduardo Bouças](/_astro/52958f21e8450baf6d8e60302341a984e220c0cd-512x512_13VDlu.webp)
    
    Eduardo Bouças
    

News & Announcements June 24, 2026

[

### How we measure Netlify’s Agent Experience

](/blog/how-we-measure-netlify-agent-experience)

-   ![Profile picture of Sean Roberts](/_astro/bbf2243f8171dbddd80ab2103622106cef84d125-512x512_Z1d2LKE.webp)
    
    Sean Roberts
    

![](/_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/)