Skip to content

WordPress login redirect loop: the full fix

A WordPress login redirect loop pushes admins back to wp-login after every attempt. Here is what causes a WordPress login loop and how to clear it without losing the session table.

A WordPress login loop is a specific failure: you enter credentials, you land briefly on /wp-admin/, you bounce straight back to /wp-login.php. No error message, no rejected password — just the polite expulsion. The cause is almost always cookie misconfiguration, and the fix lives in one of four constants or one redirect rule.

What’s happening

WordPress sets an auth cookie when login succeeds. The next request includes the cookie, WordPress validates it against the user session, and if the validation fails, is_user_logged_in() returns false and auth_redirect() bounces back to wp-login.php. The validation can fail for cookie reasons (wrong domain, wrong path, wrong scheme), session reasons (the row in wp_usermeta for the session token doesn’t match), or constant reasons (COOKIE_DOMAIN set to a value that doesn’t match the request hostname).

Common triggers: the site URL was changed without updating COOKIE_DOMAIN, Cloudflare is set to “Flexible SSL” so cookies flagged Secure can’t be read back, a multisite install has the wrong SUBDOMAIN_INSTALL value, or a security plugin’s two-factor flow is rejecting the cookie.

How to verify

curl -i -c cookies.txt -d "log=admin&pwd=password&wp-submit=Log+In" \
  https://example.com/wp-login.php
grep -i set-cookie cookies.txt
curl -i -b cookies.txt https://example.com/wp-admin/
wp config get COOKIE_DOMAIN
wp config get COOKIEHASH
wp option get siteurl
wp option get home

In the browser, open DevTools > Application > Cookies. After a failed login attempt, check whether the wordpress_logged_in_* cookie appears and what domain it’s scoped to. If it shows domain=.example.com but the request is for example.com without www, the cookie won’t be sent.

The fix

  1. Match COOKIE_DOMAIN to the request hostname. If your site is https://www.example.com, COOKIE_DOMAIN should be www.example.com or .example.com. If it’s set to something else, the browser saves the cookie but never sends it back.
  2. Fix Cloudflare SSL mode. “Flexible” means Cloudflare-to-origin is HTTP, so cookies flagged Secure won’t make it back. Switch to “Full (strict)” with a real cert.
  3. Set FORCE_SSL_ADMIN correctly. define('FORCE_SSL_ADMIN', true); requires the origin to actually receive HTTPS. If a reverse proxy terminates SSL, also set $_SERVER['HTTPS'] = 'on'; from a trust-the-proxy snippet in wp-config.php.
  4. Clear sessions. wp user session destroy --all for the user that’s looping. Sometimes the session table has a stale token that fails validation.
  5. Disable security plugins temporarily. Wordfence, iThemes, two-factor plugins — disable, try login. If it works, one of those was rejecting the post-login redirect.
  6. Check redirect plugins. A redirect from /wp-admin/ to a custom landing page that itself isn’t accessible can look like a loop. Disable Redirection or your role-redirect plugin and retest.

For multisite or multi-environment installs where login behavior needs to stay consistent, Stack Harbor enforces the cookie configuration in enterprise WordPress hosting operations. To get a stuck login fixed, book a consult.