How to Fix “Error Establishing a Database Connection” in WordPress: Complete Guide (2025)
Your WordPress site is down. Instead of your homepage, you see a plain white…
WordPress Login Page Keeps Refreshing or Redirecting
This error happens when you try to log into your WordPress dashboard and instead of landing on the admin screen, the browser just reloads the login page. You type your username and password, click Log In — and end up right back at the same form. No error message, no explanation, just an endless loop.
The frustrating part is that your credentials are usually correct. WordPress is accepting them, starting a session — and then something goes wrong before it can redirect you to wp-admin. The site essentially forgets you just logged in.
This is almost always a cookie problem. WordPress sets an authentication cookie in your browser after a successful login. If something prevents that cookie from being stored or read back — a URL mismatch, a broken config file, or a caching plugin — the login system can’t confirm who you are and sends you back to start.
You should see: A fresh login page with no pre-filled fields. Attempt to log in before moving on.
You should see: If login succeeds here, your browser’s stored cookies were the culprit. If the loop continues, move to Step 3.
define('WP_HOME', 'https://yourdomain.com');
define('WP_SITEURL', 'https://yourdomain.com');
Replace the URL with your actual address. Use the exact format your site runs on — include “www” if your site uses it, and “https” if SSL is active. These values override whatever is stored in the database.
You should see: The login page loads and you are redirected to wp-admin after submitting credentials. If this works, you have found the fix.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You should see: Successful login to wp-admin. Afterward, navigate to Settings → Permalinks and click Save Changes to let WordPress regenerate the correct .htaccess rules for your permalink structure.
You should see: Login succeeds. Rename the folder back to plugins, then go to the Plugins screen and reactivate them one at a time — testing login after each activation — until the loop returns. That last plugin is your culprit.
Get free WordPress & AI tips
Join 500+ readers. No spam, unsubscribe anytime.
No. Every step in this guide — editing wp-config.php, resetting .htaccess, and temporarily disabling plugins — leaves your posts, pages, media files, and database records completely untouched. These are configuration-level changes only.
Use phpMyAdmin to edit your database directly. Open the wp_options table and find the rows with option_name values of siteurl and home. Update both option_value fields to your correct site URL, save the changes, and try navigating to wp-login.php again.
Almost certainly yes. When a site moves to HTTPS, the old HTTP address often remains in the database. WordPress sets the login cookie for the HTTPS origin, but the stored URL is still HTTP — the browser treats these as different hosts and discards the cookie. Adding WP_HOME and WP_SITEURL in wp-config.php with the https:// prefix corrects this immediately.
Open your caching plugin’s settings and locate its page exclusion or exception list. Add /wp-login.php and /wp-admin/ as paths that must never be cached. This tells the plugin to always serve those pages dynamically, allowing WordPress to process credentials and set session cookies correctly every time.