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
- Log in to your WordPress admin dashboard.
- Go to “Settings” > “General.”
- Update the “WordPress Address (URL)” and “Site Address (URL)” fields with the correct site URL (e.g., https://www.example.com). Make sure to include “http://” or “https://” depending on your site’s setup.
- 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.
- Connect to your website using an FTP client or File Manager through your web hosting control panel.
- Locate the wp-config.php file in the root directory of your WordPress installation.
- 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', 'https://www.example.com'); define('WP_SITEURL', 'https://www.example.com');
Replace https://www.example.com with your correct site URL, including “http://” or “https://” as needed.
- 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.
- Log in to your web hosting control panel (e.g., cPanel, Plesk).
- Open phpMyAdmin and select the database used by your WordPress site.
- Find the wp_options table (the table prefix “wp_” may be different if you’ve set a custom prefix during the installation).
- Click the “Browse” button next to the wp_options table.
- Locate the siteurl and home options in the “option_name” column.
- 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., https://www.example.com). Make sure to include “http://” or “https://” as needed.
- 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.