Why does the WordPress REST API return 401 even with the right application password?
A fast test to tell whether your password is wrong or the request never reaches WordPress, the common host-level cause, the usual fix, and what still works while it is broken.
3 min read
In short: If you get 401 with rest_not_logged_in even though your application password is right, the password is probably not the problem. On some hosts the login header never reaches WordPress at all. There is a quick test to prove it, and a common fix.
I hit this while pulling the content out of a WordPress site I was migrating. The password had been created correctly. WordPress still said no.
The test that tells you which problem you have
Send a request with a username and password that you know are wrong, to an endpoint that needs a login:
curl -i -u "fakeuser:fakepass" https://example.com/wp-json/wp/v2/users/me
Then send the same request with your real details.
If WordPress knew your password was wrong, the two responses would differ: a bad login normally gets incorrect_password or invalid_username. If both return the identical rest_not_logged_in, WordPress is not seeing your credentials at all. It never received them.
A second clue: open /wp-json/ and look at the authentication section. If it is empty, WordPress has no idea authentication is available on that request.
Why it happens
On many hosts, including those running LiteSpeed or PHP in CGI mode, the web server drops the Authorization header before passing the request to PHP. Application passwords travel in exactly that header, so WordPress sees an anonymous visitor.
The common fix
If you can edit the .htaccess file in your site's root, a widely used fix is to pass the header through. Add this line inside the mod_rewrite block, after RewriteEngine On:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Back up the file first, then repeat the test. If you cannot edit it, ask your host to forward the Authorization header. I had no access to the host's settings on this project, so I did not apply this one. Treat it as the standard remedy, not a guarantee for every setup.
Other causes worth ruling out
- No HTTPS. Application passwords generally require a secure connection.
- Application passwords switched off. A security plugin or a code filter can disable them.
- A security plugin or firewall blocking REST requests. Try pausing it briefly on a staging copy.
- The wrong username. Application passwords belong to a specific user, so use that user's login name, not an email address unless that is the login.
What still works while it is broken
Published content is public. Posts, pages, categories, tags and media can be read from the REST API with no login at all, which is enough for a full export of a live site. What you cannot reach without authentication: drafts, private posts, authors and anything stored by plugins, such as SEO fields.
My workaround was in two parts. Public data came from the open REST API. The private parts came from WordPress's own export under Tools, then Export. Shop data came through the shop plugin's separate keys. That was enough to export the whole site without ever getting the application password to work.
When to stop debugging
If a header test and a plugin check do not move it within an hour, the cause is usually at the host, not in WordPress. Asking the host one precise question ("is the Authorization header forwarded to PHP?") is faster than another afternoon of guesses.
Working on a site that needs moving, connecting or cleaning up? The web design page shows what I take on, or send me the problem.
Frequently asked questions
What does rest_not_logged_in mean?
WordPress treated the request as anonymous. Either no credentials arrived or they were rejected before WordPress could check them.
Why does a fake username give the same error as my real one?
Because WordPress never saw either. If both fail identically, the Authorization header is probably being dropped before it reaches WordPress.
Can I still export my WordPress content without authentication?
Published posts, pages, categories, tags and media, yes, through the public REST API. For drafts, authors and plugin data, use WordPress's built-in export.
Do application passwords need HTTPS?
Generally yes. Without a secure connection WordPress normally hides or disables them.