Skip to content
HTTP status codes3 min read

401 Unauthorized: why the site asks you to log in

401 Unauthorized

Short answer

A 401 Unauthorized error means the server wants proof of who you are before showing the page, and it didn't receive a valid username and password or access token. Fix it by entering the right credentials, removing the folder protection in cPanel, or sending a correct Authorization header with API requests.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What causes a 401 error
  2. Fixing it as a visitor
  3. Fixing it as the site owner
  4. Prevention
  5. On ArabyHost

A 401 response carries a WWW-Authenticate header telling the browser or client which kind of login is expected. That’s why it sometimes appears as a pop-up asking for a username and password, and sometimes as JSON like {"message": "Unauthenticated."} from an API. Either way, the request arrived without a valid identity.

What causes a 401 error

  • A password-protected folder set in cPanel or with AuthType Basic rules in .htaccess, and the credentials entered (or saved in the browser) are wrong.
  • An expired session or deleted cookies, so the site asks you to log in again.
  • A missing or expired API token: no Authorization header, an old token, or the wrong format.
  • The Authorization header never reaches PHP: some PHP handlers don’t pass it on by default, so the app thinks you sent nothing.
  • A WordPress security plugin adding an extra password to wp-admin or blocking the REST API for guests, which returns rest_not_logged_in.

Fixing it as a visitor

  1. Check that the URL is correct and that you actually have an account on the site.
  2. Retype the username and password by hand, watching the keyboard language and letter case.
  3. Try a private window, because the browser may keep sending old saved credentials.
  4. If you don’t have access, contact the site owner.

Fixing it as the site owner

1. Check folder protection

In cPanel open Files → Directory Privacy and pick the folder (for example public_html or wp-admin). If the protection isn’t intended, untick “Password protect this directory”, or create a new user with a known password. The feature writes rules like these into .htaccess:

AuthType Basic
AuthName "Protected"
AuthUserFile "/home/USER/.htpasswds/public_html/passwd"
Require valid-user

If you find these lines in your .htaccess file and didn’t add them, remove them or find out who did.

2. Fix the Authorization header for API apps

Test the request by hand:

curl -i -H "Authorization: Bearer YOUR_TOKEN" https://example.com/api/me

If the token is right and you still get 401, add this at the top of .htaccess so the header is passed to PHP:

RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

This is a common fix for Laravel Sanctum and WordPress Application Passwords. Keep API keys in environment variables, never in front-end code.

3. Review WordPress security plugins

If the error started after installing a security plugin, disable it by renaming its folder inside wp-content/plugins in File Manager, then reconfigure it. Our WordPress security guide covers settings that don’t lock out legitimate users.

Prevention

  • Document every folder you password-protect and keep the credentials in a password manager.
  • Use API tokens with narrow permissions and rotate them before they expire.
  • In your code, keep 401 (not logged in) separate from 403 (logged in but not allowed) so the messages make sense.

On ArabyHost

cPanel opens with one click from the Araby Panel, and that’s where Directory Privacy and File Manager live. Sites run on LiteSpeed, which reads .htaccess like Apache, so the rules above work as written. The Araby AI assistant can read your error log and explain why requests are being rejected. If a server-side security rule is the cause, support can review the ModSecurity or Imunify360 block.

FAQ

What's the difference between 401 and 403?

A 401 means the server doesn't know who you are and wants you to log in. A 403 means it either knows you or doesn't care, but you are not allowed on that page whatever credentials you send.

Why does a box asking for a username and password pop up before the site loads?

That's HTTP Basic authentication set at the server, usually through Directory Privacy in cPanel or an .htaccess file. Enter the right credentials or remove the protection and the 401 goes away.

Why does my API return 401 even though I send the correct token?

On some server setups the Authorization header doesn't reach PHP. Add an .htaccess rule that passes it through to your app, and check that the token hasn't expired.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.