Contents
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 Basicrules 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
Authorizationheader, an old token, or the wrong format. - The
Authorizationheader 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-adminor blocking the REST API for guests, which returnsrest_not_logged_in.
Fixing it as a visitor
- Check that the URL is correct and that you actually have an account on the site.
- Retype the username and password by hand, watching the keyboard language and letter case.
- Try a private window, because the browser may keep sending old saved credentials.
- 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.