Skip to content
  • GDPR-compliant
  • 100% hosting in Germany
  • Personal contact
  • Support included
  • Provisioning within 24 hours
Error & Status Codes 2 min read

HTTP status code 401 Unauthorized: causes and solutions

In short

A 401 Unauthorized means: this page requires authentication, and no valid credentials were sent. With the correct credentials, the page is accessible.

What does status code 401 mean?

The server knows the requested page but only releases it after successful authentication. Together with the status code, it sends the WWW-Authenticate header, which specifies how to authenticate. With classic directory protection, the browser then opens the familiar login dialog.

401 or 403 - what is the difference?

  • 401 Unauthorized: you are not logged in or the credentials are wrong. With valid credentials you get access.
  • 403 Forbidden: the server knows who you are but refuses access in principle - for example due to missing permissions, blocked IP addresses or a firewall rule.

Typical causes

  • Directory protection (.htaccess + .htpasswd) protects the area, and the credentials are missing or wrong.
  • The credentials were changed, but the browser still sends the old ones.
  • The path to the .htpasswd in the .htaccess is incorrect, for example after moving the website.
  • For applications and interfaces (APIs): an expired session, a missing or invalid API key or token.

Solution for visitors

  • Check your user name and password - mind upper and lower case.
  • Browsers remember directory protection credentials until they are closed. Close all browser windows or test in a private window.
  • Log out of web applications once and log in again.
  • If the error persists, contact the operator of the website.

Solution for site operators

The easiest way to set up directory protection is in the control panel: KeyHelp and Plesk both offer a directory protection feature. There you create protected folders and users without editing files yourself.

Alternatively, create the protection manually. The .htaccess in the folder to protect:

AuthType Basic
AuthName "Protected area"
AuthUserFile /absolute/path/to/.htpasswd
Require valid-user

Create the .htpasswd via SSH with secure encryption (bcrypt):

htpasswd -c -B /absolute/path/to/.htpasswd username

You will then be asked for the password twice. Important: the option -c creates the file anew and overwrites an existing one. Therefore, add further users without -c:

htpasswd -B /absolute/path/to/.htpasswd another-user

Tips for secure directory protection

  • Store the .htpasswd outside the publicly accessible web directory whenever possible.
  • Only use directory protection over HTTPS - credentials are transmitted when logging in.
  • Use separate credentials for each user and remove entries that are no longer needed.
  • Directory protection is well suited as additional protection for test and staging environments or admin areas.

You can find failed login attempts in the logs of your website: How do I read my log files?

Was this article helpful?

New to SpeedIT Solutions?

Hosting where you know someone.

What you are reading here is what we put into practice for our customers every day. Based in Isernhagen since 2009 - with dedicated contact persons rather than a call centre.

  • 100% hosted in Germany
  • GDPR-compliant
  • Dedicated contact person
  • Provisioning within 24 hours
4.9 88 reviews on Expeero

gute Erreichbarkeit

sehr guter Service
Gerhard G.Recommends us · 08/07/2026

100 % recommend us · Expeero

All reviews on HOSTtest (opens in a new window)

You might also be interested in:

Personal support

Of course, our support team is also happy to assist you personally. If you cannot find what you are looking for in our knowledge base or require personalised support, please do not hesitate to contact us. We’re here to help you and to ensure that your experience with our products and services is as smooth and enjoyable as possible.