+254725682556 +254725052660 info@ziprof.co.ke
Client Area

WordPress

How to Fix WordPress Redirecting to the Wrong URL

When WordPress keeps redirecting to the wrong domain, an old URL, or bounces your browser in an endless loop, the cause is almost always a mismatch between the address you're trying to visit and the site address WordPress has stored internally. This commonly happens after you move your site to a new domain, switch from http to https, add or remove "www," or restore a backup from a different environment.

Why This Happens

WordPress stores two core settings, the WordPress Address (URL) and the Site Address (URL), in its database. Every page load checks these values. If they still point to an old domain, the wrong protocol, or a different "www" prefix than what you're actually using, WordPress will try to send visitors to that stored address instead, which shows up as a wrong-URL redirect or a redirect loop.

Before changing anything, back up your WordPress database. If a fix doesn't work as expected, you'll want a way to undo it.

How to Fix It

Option 1: From the WordPress Dashboard (if you can still log in)

  1. Log in to wp-admin.
  2. Go to Settings, then General.
  3. Check the WordPress Address (URL) and Site Address (URL) fields. Both should match the exact domain, protocol (http or https), and "www" or non-"www" form you actually use to reach your site.
  4. Correct any mismatch and click Save Changes.

Option 2: Edit wp-config.php (if you're locked out or the dashboard also redirects)

If a wrong URL is causing a redirect loop before the dashboard even loads, you won't be able to use Option 1. Instead, add the correct values directly to your site's configuration file:

  1. Open your hosting control panel's File Manager (in cPanel or DirectAdmin) and navigate to your website's root folder.
  2. Right-click wp-config.php and choose Edit.
  3. Add these two lines just above the line that reads /* That's all, stop editing! */, replacing the example domain with your real one:
    define('WP_HOME','https://yourdomain.com');
    define('WP_SITEURL','https://yourdomain.com');
  4. Save the file and reload your website.

These two lines override whatever is stored in the database, so they're a safe way to force the correct address without touching your data directly.

Option 3: Fix It Directly in the Database (if Options 1 and 2 aren't available)

  1. Open phpMyAdmin from your hosting control panel and select your WordPress database.
  2. Open the wp_options table (the prefix may differ if you customized it during install).
  3. Find the rows where option_name is siteurl and home.
  4. Click Edit on each row and update the option_value to your correct, full web address, including https:// if you use SSL.
  5. Click Go to save each change.

Clearing Up the Redirect Loop

After applying a fix, clear your browser cache or open the site in a private/incognito window before testing. Browsers aggressively cache redirect responses, so you may still see the old redirect even after the underlying setting is corrected.

If This Started After Enabling HTTPS

A very common trigger is turning on an SSL certificate without updating the site address to match. If that's your situation, make sure both the WordPress address settings above and your site-wide redirect rules point consistently to https://. See How to Force HTTPS and Redirect All Traffic to Your Secure Website for setting up that redirect correctly alongside this fix.