Skip to Content

WordPress Keeps Redirecting to Localhost? A Quick Troubleshooting Guide

WordPress Keeps Redirecting to Localhost? A Quick Troubleshooting Guide

WordPress is a very popular content management system (CMS) that is used by millions of people all over the world. While it is a great platform, there can be times when it starts to act up. One of the most common issues is – WordPress keeps redirecting to localhost.

Don’t panic. We are here to help. In this article, we’ll show you how to fix the redirect issue in just a few minutes and get your WordPress site up and running again.

What is WordPress Localhost?

WordPress localhost is a server that runs WordPress and provides an environment for you to develop and test your WordPress site. You can use it to create, edit, and delete content, as well as install themes and plugins on your site.

Localhost is not publicly accessible, so you will need to upload the files created in your local environment to a web server before anyone else can see them.

Why is my WordPress redirecting to Localhost?

  • Your WordPress URL settings are incorrect.
  • Any faulty plugin is creating a conflict.
  • .htaccess file has become corrupted.
  • Your activated WordPress theme is having a compatibility issue.

How do I stop WordPress from redirecting to localhost?

Update URL settings

WordPress settings include its installation URL and website URL. If these URLs are incorrect, it will redirect you to its Localhost, preventing you from accessing the admin page. To manually update the URL settings, do the following:

  • Use FTP or your host’s cPanel and access the File Manager. 
  • Locate the wp-config.php file and edit it. 
  • Now paste the following lines of code:
define('WP_HOME','https://www.yoursite.com'); 
define('WP_SITEURL','https://www.yoursite.com');
  • Next, save the changes and launch WordPress to see if the issue is fixed.

Note: Make sure to replace ‘yoursite’ in the above example with your website domain name before updating the URL Settings.

Edit wp-options

Sometimes, the redirecting issue arises when you restore the WordPress website backup from localhost to the live server. To resolve the issue, you have to edit the wp-options in the following way:

  • Log in to your host cPanel and locate the PhpMyAdmin icon from the menu.
  • Now, select the Database of your WordPress website and then click on wp-options. You will see that the site URL is set to your localhost.
  • Change the URL to your website domain name and click on the Go option.
  • Now, launch WordPress admin and if the issue is resolved, head over to the Setting>General Settings.
  • Next, change the Site URL to the domain name and click on the Save changes option.

Delete .htaccess file

Another reason your WordPress redirects to localhost is a corrupted .htaccess file, which causes an internal server error. To fix the issue, delete the file from the cPanel by following the steps below:

  • Access the File Manager via cPanel and find the .htaccess file.
  • Next, download the .htaccess file and save it on your PC as a backup.
  • Now, delete the .htaccess file from the hosting panel.
  • Also, check the wp-admin folder and delete the .htaccess file there. 
  • Now try accessing your WordPress. If the issue is fixed, navigate to Settings from your dashboard. 
  • Finally, Click on Permalinks and apply the new changes.

Deactivate the faulty plugin

If you have installed a plugin that is not compatible with another active plugin, this can affect your WordPress and generate the redirecting issue. To resolve the issue, deactivate all the activated plugins manually:

  • Login to the cPanel and open the File Manager. 
  • Locate the wp-contents folder and open it. 
  • Next, click on the Plugins folder and rename it. 
  • Add  .hold or  .disable to it. 
  • Navigate to WordPress and see if the issue is resolved. 

Note: You can also deactivate plugins from the hosting dashboard. Ensure to deactivate all the plugins and activate them one by one to single out the plugin causing the conflict.

Change to the default WordPress theme

Sometimes, changing your WordPress theme can create conflict on your website with plugins or the new WordPress version, resulting in the redirecting issue. Simply deactivate the theme in the following way:

  • From your browser, access your host cPanel and navigate to the File Manager. 
  • Click on the wp-contents folder and search for the Themes folder. 
  • Now, in the theme folder, locate the activated theme file and rename it by adding .disable or .hold. 
  • Launch your WordPress and check if the redirecting issue is resolved. 

How to resolve WordPress Multisite redirect to localhost?

  • Navigate to xampp>apache>conf>extra directory>httpd-vhosts.conf file and  paste the below code lines for the first domain:
<VirtualHost *:80>
    ServerName multisite-one.com
    DocumentRoot "C:\xampp\htdocs\multisite
    <Directory  "C:\xampp\htdocs\multisite">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
  • Paste these lines of code for the second domain
<VirtualHost *:80>
    ServerName multisite-two.com
    DocumentRoot "C:\xampp\htdocs\multisite
    <Directory  "C:\xampp\htdocs\multisite">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
  • Head over to Windows>System32>drivers>etc directory and locate the host file.
  • Open it as administrator and paste the code below:
#wordpress multisite set up
127.0.0.1   multisite-one.com
127.0.0.1   www.multisite-one.com

127.0.0.1   multisite-two.com
127.0.0.1   www.multisite-two.com
  • Restart the server and then access the cPanel to put the code below in wp-config.php file:
define('WP_DEBUG', false);
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'multisite-one.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
  • Access database in PhpMyAdmin and edit path and domain in wp-blogs table while home and site URL in wp_options table.

Conclusion

This blog has listed down some common reasons why WordPress keeps redirecting to localhost and their solutions. Hopefully, you will be able to resolve the issue by following any of the above approaches.

However, if the issue is still there, get support from your hosting provider or WordPress Support Forum.

Author

  • Tauqeer Ahmed

    Tauqeer Ahmed is a technology expert with over 10 years of experience in the industry. He has a degree in Computer Science and specializes in network security and software troubleshooting. You can find out more about him at https://helpfixthat.com/tauqeer-ahmed/

Leave a comment

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