In short
Any copy of the site that is not production (staging, acceptance, development environment, preview deployment, old domain) must require server-side authentication before sending a single page. The X-Robots-Tag: noindex header is a second line of defense, never the main protection. Once the check is done, every non-production host answers an anonymous request with a 401 or 403, none of its pages is indexed, and production contains no link or setting inherited from staging.
Why it matters
An open staging site is a duplicate of the site. When Google discovers it, it finds two versions of the same content and picks the canonical itself: it sometimes keeps staging.example.com rather than the real site. Visitors then land on a test version, and external links get scattered.
Staging addresses leak faster than you think: a link pasted into a ticket or an email, a sitemap generated with the wrong host name, a canonical or hreflang tag pointing to the acceptance environment, absolute URLs left in the database after a migration, and the public Certificate Transparency logs, which list every subdomain a TLS certificate has been issued for.
Staging also holds what is not yet public: new prices, offers, pages in preparation. That content can be indexed, collected by AI crawlers or read by an assistant someone gave the URL to, then resurface in a generative answer before your announcement. And if the staging database is a copy of production, it exposes real personal data.
Neither robots.txt (a public instruction that a bot acting for a user may ignore), nor noindex (which does not prevent reading), nor a secret URL protects staging. Google lists password protection among the lasting methods for keeping content out of its results.
What it improves
- Indexing Staging no longer competes with production and can no longer be chosen as the canonical.
- Privacy Unpublished content and test data are out of reach of bots, AI assistants and strangers.
- Reliable releases Settings separated by environment avoid pushing a
noindexor aDisallow: /to production. - Compliance Protecting personal data relies on access control, not on an instruction to bots.
- Rankings No direct effect; the indirect effect is avoiding dilution between two copies.
How to check
1. List the non-production hosts. List the subdomains in your DNS zone and those that have received a certificate, with crt.sh (the command uses jq):
curl -s "https://crt.sh/?q=%25.example.com&output=json" | jq -r '.[].name_value' | sort -u
Add the platform addresses: *.vercel.app, *.netlify.app, *.pages.dev, *.webflow.io, the server’s IP address, old domains.
2. Test each host without credentials.
for h in staging.example.com preprod.example.com recette.example.com dev.example.com; do
printf "%-28s " "$h"; curl -s -o /dev/null -w "%{http_code}\n" "https://$h/"
done
Expected result: 401 or 403, or a redirect to a login page. A 200 means the host is public. Also test a file (/wp-content/uploads/…, /storage/…) and an API endpoint.
3. What is already indexed. Search for site:staging.example.com in Google and Bing, as well as an exact sentence from a recent page in quotation marks. If you have a Domain property in Search Console (it covers every subdomain), filter the Performance report on pages whose URL contains staging.
4. What production leaks.
curl -s https://example.com/sitemap.xml | grep -c "staging\."
curl -s https://example.com/ | grep -o -E "https?://(staging|preprod|recette|dev)\.example\.com[^\"' ]*" | sort -u
Expected result: 0 and no lines.
How to implement
Before you start
Principles that apply everywhere:
- Protect the whole host, files and API included, not just the pages.
- Add
X-Robots-Tag: noindex, nofollowon every non-production host. It protects nothing, but it limits the damage if the protection ever fails. - Plan exceptions explicitly: a payment provider’s webhooks, a monitoring probe, the office IP address. Nothing else.
- Separate configuration by environment: environment variable, separate host file, never a box to uncheck on launch day.
- Anonymize database copies used outside production.
- Never commit the password to the code repository.
Protection configurations per environment are detailed in protect private content with authentication (opens in a new tab). The sections below give the complete staging version, with its exceptions.
Apache
Versions Apache 2.4.
Staging virtual host, after sudo htpasswd -c /etc/apache2/.htpasswd-staging equipe:
<VirtualHost *:443>
ServerName staging.example.com
DocumentRoot /var/www/staging/public
Header always set X-Robots-Tag "noindex, nofollow"
<Location "/">
AuthType Basic
AuthName "Preproduction"
AuthUserFile /etc/apache2/.htpasswd-staging
<RequireAny>
Require ip 203.0.113.10
Require valid-user
</RequireAny>
</Location>
<Location "/webhooks/paiement">
Require all granted
</Location>
</VirtualHost>
Add your certificate directives. The /webhooks/paiement block, placed after it, lifts the protection for that path only. Reload with sudo apachectl configtest && sudo systemctl reload apache2.
Nginx
Versions Nginx 1.18 and later.
server {
listen 443 ssl;
server_name staging.example.com;
root /var/www/staging/public;
add_header X-Robots-Tag "noindex, nofollow" always;
satisfy any;
allow 203.0.113.10;
deny all;
auth_basic "Preproduction";
auth_basic_user_file /etc/nginx/.htpasswd-staging;
location /webhooks/paiement {
satisfy any;
allow all;
auth_basic off;
try_files $uri /index.php?$query_string;
}
}
With satisfy any, the allowed IP address gets through without a password; everyone else must authenticate. Add the certificates and the PHP or proxy_pass block, then sudo nginx -t && sudo systemctl reload nginx.
Cloudflare
Versions Cloudflare One (Zero Trust) dashboard and Cloudflare Pages, all plans, November 2026.
For a proxied subdomain, Cloudflare Access puts a login in front of the host: Zero Trust dashboard, Access controls > Applications, “Create new application”, type “Self-hosted and private”, on staging.example.com, with a policy limited to your email addresses or your identity provider. Add a “Bypass” policy for the webhook path only if needed. The origin must refuse traffic that does not come from Cloudflare, otherwise its IP address bypasses Access.
For Cloudflare Pages, preview deployments receive X-Robots-Tag: noindex by default but remain public. In Workers & Pages, open the project, Settings > General, then “Enable access policy”: only members of your account can then view them. This setting protects neither the production *.pages.dev address nor your custom domains.
AWS
Versions AWS Amplify Hosting, CloudFront and Elastic Load Balancing consoles, November 2026.
- Amplify Hosting: in the Amplify console, open the app,
Hosting > Access control, then “Manage access” to password-protect one branch or all branches. For an SSR app, redeploy to apply the setting. - CloudFront in front of an S3 bucket: a CloudFront function on the “viewer request” event adds Basic authentication; see the example in protect private content with authentication (opens in a new tab).
- Application Load Balancer: an “Authenticate” action with Cognito or an OIDC provider on the listener rule for the staging host.
Vercel
Versions Vercel dashboard, all plans (password protection: Pro and Enterprise), November 2026.
In Settings > Deployment Protection, enable “Vercel Authentication” with the “Standard Protection” scope: every URL except production domains is then accessible only to team members. Vercel also adds X-Robots-Tag: noindex to previews, but not when a branch is served on a custom domain such as staging.example.com: that domain must be protected, or receive the header through your configuration.
Netlify
Versions Netlify interface, Pro and Enterprise plans, November 2026.
Project configuration > General > Visitor access > Password Protection lets you password-protect non-production deploys (on credit-based Pro plans: Visitor access > Project visibility). Free plans do not have this protection. Netlify adds X-Robots-Tag: noindex to Deploy Previews and to older branch deploys, but not to the latest deploy of each branch: a published staging branch remains indexable without protection. Netlify itself states that this header is not a guarantee.
Plesk
Versions Plesk Obsidian 18.0.
Websites & Domains > staging.example.com > Password-Protected Directories, then protect /. Plesk’s WP Toolkit can create a staging copy of a WordPress site: protect it the same way and check that it is not exposed to search engines.
cPanel
Versions cPanel & WHM 110 and later, Jupiter theme.
Files > Directory Privacy: select the root folder of the staging subdomain, enable protection and create a user. Add the header in the .htaccess of the same folder:
<IfModule mod_headers.c>
Header always set X-Robots-Tag "noindex, nofollow"
</IfModule>
Shared hosting
Use the control panel’s password protection or a .htaccess in the subdomain’s folder, with the .htpasswd outside the web root. If the host provides a staging environment, check with curl that it answers 401: some only set a noindex.
WordPress
Versions WordPress 5.7 to 7.1; WP-CLI 2.
Do not count on the visibility box in Settings > Reading: it protects nothing and often ends up copied to production. Protect the host at server or hosting level, then declare the environment in the staging wp-config.php:
define('WP_ENVIRONMENT_TYPE', 'staging');
Then add, in a must-use plugin (wp-content/mu-plugins/environnement.php), a directive that never applies in production:
<?php
add_filter('wp_robots', function (array $robots): array {
if (wp_get_environment_type() === 'production') {
return $robots;
}
$robots['noindex'] = true;
$robots['nofollow'] = true;
return $robots;
});
Without the constant, wp_get_environment_type() returns production: production is not affected. After copying the database to production, replace the staging URLs with WP-CLI, starting with a dry run:
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run
Shopify
Versions Shopify admin, all plans, November 2026.
Shopify has no separate staging host. Test your changes in an unpublished theme: its preview links (preview_theme_id) are disallowed from crawling in the default robots.txt. For a development store or before launch, keep the password active: Online Store > Preferences, “Store access” section, “Private mode” setting.
Webflow
Versions Webflow interface (site settings), November 2026.
The *.webflow.io subdomain serves as staging. In the site settings, SEO section, the option that disables indexing of the Webflow subdomain (paid plan) works through robots.txt: it prevents neither reading nor the indexing of URLs that are already known. For a confidential project, use the site’s password protection, depending on your plan.
Laravel
Versions Laravel 10 to 13.
Protect the host at web server level: that way the protection covers static files. In addition, add a global middleware that sets the header outside production:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class NoIndexOutsideProduction
{
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
if (! app()->isProduction()) {
$response->headers->set('X-Robots-Tag', 'noindex, nofollow');
}
return $response;
}
}
Set APP_ENV=staging in the staging .env and APP_URL to its own host, so that generated URLs (sitemap, canonical, emails) do not mix environments. Only the middleware registration changes with the version.
Laravel 11 to 13
Since Laravel 11, global middleware is registered in bootstrap/app.php:
use App\Http\Middleware\NoIndexOutsideProduction;
use Illuminate\Foundation\Configuration\Middleware;
// ...
->withMiddleware(function (Middleware $middleware): void {
$middleware->append(NoIndexOutsideProduction::class);
})
Laravel 10
Add the class at the end of the $middleware array in app/Http/Kernel.php:
protected $middleware = [
// ...
\App\Http\Middleware\NoIndexOutsideProduction::class,
];
Laravel 10 has no longer received security fixes since February 2025: plan the upgrade.
Next.js
Versions Next.js 13 to 16, App Router and Pages Router.
On Vercel, use Deployment Protection. When self-hosting, Basic authentication can be set in the Next.js proxy, a file placed at the project root (or in src/):
import { NextResponse } from 'next/server';
export function proxy(request) {
if (process.env.APP_ENV === 'production') {
return NextResponse.next();
}
const expected = `Basic ${btoa(`${process.env.STAGING_USER}:${process.env.STAGING_PASSWORD}`)}`;
if (request.headers.get('authorization') === expected) {
const response = NextResponse.next();
response.headers.set('X-Robots-Tag', 'noindex, nofollow');
return response;
}
return new NextResponse('Authentication required', {
status: 401,
headers: { 'WWW-Authenticate': 'Basic realm="Preproduction"' },
});
}
The credentials come from the host’s environment variables, never from the repository. Protection by the web server or the proxy in front remains preferable. Only the file name and the function name change with the version.
Next.js 16
Save this code in proxy.js. Since Next.js 16, the proxy runs on the Node.js runtime by default.
Next.js 13 to 15
Save this code in middleware.js and rename the function:
// middleware.js
export function middleware(request) {
// …
}
The middleware convention is deprecated since Next.js 16: when upgrading, npx @next/codemod@canary middleware-to-proxy . renames the file and the function.
Clean up a staging site that is already indexed
- Protect the host first: with a lasting 401, the pages leave the index as they are crawled and can no longer come back.
- Request a temporary removal: in Search Console’s Removals tool, “New request”, enter
https://staging.example.com/and choose “Remove all URLs with this prefix”. The tool requires you to own a property that covers this host; a Domain property, verified through DNS, covers every subdomain and remains usable even when the host is protected. The removal lasts about six months: the protection makes it permanent. - Bing: Bing Webmaster Tools’ Block URLs tool temporarily hides a directory or a host; the protection does the rest.
- Clean up production: sitemaps, canonical, hreflang, internal links and content pointing to staging.
- If the host is abandoned, a 301 redirect from each URL to its production equivalent consolidates any links it may have received.
Private data outside staging
Customer areas, internal documents and production APIs follow the same rule: server-side authentication, files served after a check, Cache-Control: private, no-store. See protect private content with authentication (opens in a new tab) and the access policy in protect private information with access control (opens in a new tab).
Common mistakes
Disallow: /as the only protection: staging remains readable, and a blocked URL can be indexed without content. The file also sometimes ends up copied to production.- A password on the pages but not on the files: PDFs and images in
uploadsremain accessible through their URL. - A staging branch on a custom domain at Vercel or Netlify: the automatic
noindexheader is no longer set there. - Pushing staging to production by copying files:
.htaccess,robots.txtandnoindexsettings go along with it. See remove accidental noindex tags (opens in a new tab). - Copying the production database to the acceptance environment without anonymizing it: personal data is then exposed with every leak.
- Using the Removals tool without protecting the host: the pages come back after about six months.
Frequently asked questions
How do I stop Google from indexing a staging site?
Protect the whole staging host with server-side authentication that answers anonymous requests with a 401 or 403: HTTP Basic authentication on Apache or Nginx, control panel protection, Cloudflare Access, or Vercel, Netlify or Amplify deployment protection. Add the X-Robots-Tag noindex header on top. A robots.txt that blocks everything is not enough: it protects nothing and a blocked URL can still be indexed.
My staging site is already in Google: what should I do?
First protect the host with authentication, so that the pages can no longer be read or reindexed. Then request a temporary removal in Search Console’s Removals tool, with the option that removes every URL starting with the host’s prefix; it usually takes effect within a day and lasts about six months. Finally, remove from production any link, sitemap or canonical that points to staging.
Is Vercel’s or Netlify’s automatic noindex enough?
No. Vercel and Netlify add X-Robots-Tag noindex to preview deployments, but these addresses remain public: anyone, AI crawlers included, can read them if the URL gets around. The header is not set on a branch served on a custom domain at Vercel, nor on the latest branch deploy at Netlify. Enable the platform’s deployment protection for sensitive environments.
Does staging need a password if it is blocked in robots.txt?
Yes. Robots.txt is a public instruction that bots choose to follow, and some bots acting on behalf of a user, such as AI assistants, may not apply it when given a URL. A blocked URL also remains indexable without content if links point to it. Only server-side authentication prevents reading staging’s pages, files and APIs.
Resources
- Google: Control what you share with Googledevelopers.google.com
- Google: Remove information from Searchdevelopers.google.com
- Google: Search Console Removals toolsupport.google.com
- Vercel: Are Vercel preview deployments indexed by search engines?vercel.com
- Netlify: deploy overview and indexingdocs.netlify.com
- Cloudflare Pages: Preview deploymentsdevelopers.cloudflare.com
- AWS Amplify: Restricting access to branchesdocs.aws.amazon.com
- WordPress: wp_get_environment_typedeveloper.wordpress.org
- Nginx: auth_basic module and Apache: Authentication and Authorizationnginx.org
Updated on
Topic checklist (PDF)