How to prevent a redirection to localhost in a WordPress site

If you’re experiencing a redirect to localhost in your WordPress site, it’s likely due to incorrect site URL settings in your WordPress configuration. To fix this issue, you can update your site URL settings using one of the following methods:

Method 1: Update Site URL in the WordPress Dashboard

  1. Log in to your WordPress admin dashboard.
  2. Go to “Settings” > “General.”
  3. Update the “WordPress Address (URL)” and “Site Address (URL)” fields with the correct site URL (e.g., Make sure to include “http://” or “https://” depending on your site’s setup.
  4. Click “Save Changes” at the bottom of the page.

Method 2: Update Site URL using wp-config.php

If you cannot access your WordPress dashboard due to the redirect issue, you can update the site URL settings directly in the wp-config.php file.

  1. Connect to your website using an FTP client or File Manager through your web hosting control panel.
  2. Locate the wp-config.php file in the root directory of your WordPress installation.
  3. Open the file for editing and add the following lines just above the line that says /* That’s all, stop editing! Happy publishing. */:
define('WP_HOME', '');
define('WP_SITEURL', '');

Replace with your correct site URL, including “http://” or “https://” as needed.

  1. Save the changes and upload the updated wp-config.php file back to your server if necessary.

Method 3: Update Site URL using phpMyAdmin

If the previous methods don’t work, you can update the site URL settings directly in your WordPress database using phpMyAdmin.

  1. Log in to your web hosting control panel (e.g., cPanel, Plesk).
  2. Open phpMyAdmin and select the database used by your WordPress site.
  3. Find the wp_options table (the table prefix “wp_” may be different if you’ve set a custom prefix during the installation).
  4. Click the “Browse” button next to the wp_options table.
  5. Locate the siteurl and home options in the “option_name” column.
  6. Click the “Edit” button (usually a pencil icon) for each of these options and update the “option_value” field with the correct site URL (e.g., Make sure to include “http://” or “https://” as needed.
  7. Click “Go” or “Save” to save the changes for each option.

After following one of these methods, the redirect to localhost issue should be resolved. Remember to clear your browser cache and, if you’re using a caching plugin, clear your WordPress cache as well to see the changes.

Leave a Reply

Your email address will not be published. Required fields are marked *