How to set a password for deploy previews

For our public website, we are using netlify to deploy the master branch (which would be something like, and also have a deploy preview for each PR to master (which will be e.g., My questions are:

  • How to set a password only for the deploy previews?
  • Are publicly accessible deploy previews indexed by search engines?


You can do this with a combination of Deploy Contexts and Basic Authentication via _headers.

There’s a blog article explaining the premise here:

The pieces are:

  • The context in the netlify.toml lets you identify which branch is building.
  • You run a different script when you need to.
  • The ‘branch only’ script copies a _headers file (with credentials) into the output.

They can be.

However you can also use the above idea to build a different robots.txt file into the output of your branch builds… or to pass in a build flag that you inspect to generate <meta name="robots" content="noindex"> into every page.

1 Like

Thanks so much for sharing that thorough post, @nathanmartin. This is great information! @sedghi, let us know if you need any additional answers.