Find out what's asking your visitors to sign in

401 Unauthorized means the server refused the request because it came without valid credentials, and it's asking the client to authenticate. On a public site, look for password protection that covers pages meant for everyone, such as a staging lock that stayed on at launch, or a sign-in rule at a proxy or load balancer. The WWW-Authenticate header in the response names the kind of credentials the server wants, and that points to what's asking.

Where a 401 comes from

  • Password protection on the server

    A web server set to protect a folder or the whole site with HTTP Basic authentication answers every request without the password with 401, and the browser shows a sign-in box. If a staging lock was copied to production, every visitor gets that box.

  • A sign-in rule at a load balancer or proxy

    A load balancer or proxy can require sign-in before it forwards a request, and it answers 401 when that rule turns the visitor away or the identity provider refuses them.

  • An app or API without a valid token

    Your app sends 401 when a session has expired or an API call arrives without a valid token. For token-based APIs, the challenge names a scheme such as Bearer.

  • A signed-in user without permission

    Some servers answer 401 even after sign-in succeeds, when the user isn't allowed into that area. Apache does this by default unless it's set to send 403 instead.

RFC 9110 requires every 401 to carry a WWW-Authenticate header with at least one challenge. Amazon's load balancer guide describes the 401s its sign-in rules send, and Apache's authorization reference its default for a failed authorization.

Read the challenge your server sends

# Print the status and the challenge that came with it
curl -sI https://yoursite.com/ | grep -iE '^(HTTP|www-authenticate)'

# Check a deeper page and an asset too; a lock can cover one folder only
curl -sI https://yoursite.com/blog/ | grep -iE '^(HTTP|www-authenticate)'
curl -sI -o /dev/null -w '%{http_code}\n' https://yoursite.com/favicon.ico

What the challenge tells you

  • A challenge that starts with Basic, such as Basic realm="Staging", comes from HTTP Basic authentication, set in the web server's configuration, an .htaccess file or your host's password protection setting. The realm is text the owner chose to describe the protected area, so it often says which lock you're looking at. MDN's authentication guide explains the scheme.

  • Bearer points to an app or API that expects a token, so look at your app's sign-in and session handling. A 401 with no WWW-Authenticate header at all breaks the rule in RFC 9110, which usually means app code that sets the status by hand; search your code for where it returns 401.

How to fix a 401 Unauthorized error

  1. Map where the lock appliesRun the curl commands against the home page, a few inner pages and a static file. A 401 everywhere points to a site-wide setting, and a 401 under one path points to a rule for that folder.
  2. Take the lock off public pagesRemove the Basic authentication rule, or turn off the host's password protection, for everything visitors should reach. Keep sign-in only on staging copies and admin areas.
  3. Send 403 when signing in won't helpIf a signed-in user lacks permission for an area, answer 403 instead of 401, so browsers and apps stop asking for credentials that can't work.
  4. Let Googlebot reach pages you want indexedGooglebot doesn't sign in. For a page you want in search results, remove the sign-in requirement, or let Googlebot through after confirming its requests come from Google.

Frequently asked questions

What's the difference between 401 and 403?

A 401 says the request came without valid credentials, so signing in could fix it. A 403 says the server refuses the request even with the credentials it got, because the account lacks permission or a rule blocks it, so signing in again changes nothing. MDN's 403 page draws the same line.

Why does Search Console say blocked due to unauthorized request?

Google's crawler got a 401 when it requested the page, and the status reads Blocked due to unauthorized request (401). Google suggests removing the authorization requirement or allowing verified Googlebot requests, and checking the page in a private browser window to see what a visitor without your saved sign-in gets. The Page indexing report guide describes the status.

Is HTTP Basic authentication safe for a staging site?

Only over HTTPS. Basic authentication sends the username and password encoded but not encrypted, so anyone who can read the traffic can recover them. MDN's authentication guide warns about this.