How to Move a WordPress Site from a Subdomain to the Root Domain

How to Move a WordPress Site from a Subdomain to the Root Domain

A subdomain is a great way to keep certain parts of your site separate from its primary purpose. For example, let’s say you run a WooCommerce store. Most of the action takes place at the root domain where your customers shop for the products they need or want. Now, as you add new items to your store, you might want to update your customers about them. So, you could make a blog in a subdomain where you publish posts describing the new additions and perhaps even have visitors sign up for a newsletter.

As another example, you might use a subdomain as a permanent staging environment for the development and testing of your live site. Now, there may come a time when you consider moving the subdomain to your root domain. How do you go about doing so? In this article, I’ll show you how to move a WordPress site from a subdomain to a root with step-by-step instructions.

TL;DR: Migrating WordPress from subdomain to main domain can be a little risky. You can eliminate this risk by using the excellent free plugin Migrate Guru. Migrate Guru will do all the heavy lifting for you, moving your site safely and quickly to the root domain in a few clicks. Moreover, it works with all web hosts out of the box.

What to do before you move WordPress from subdomain to root

Like moving a website to a new host or domain, you can transfer WordPress from subdomain to root either the easy way via a plugin or the hard way by doing it yourself. I’ll cover both approaches in this article. But before you start, it’s a good idea to do the following:

  • Back up your entire site, i.e., the WordPress files and databases for both the subdomain and the root domain. If anything goes wrong during the migration, you can revert to a fully functional version of your site and start again.
  • Clear everything cached by any caching plugins that you use, then disable said plugins as they can cause issues during migration. Re-enable them on your site after the migration is complete.
  • Put your site in maintenance mode using a plugin like Themeisle’s WP Maintenance Mode & Coming Soon. It will ensure that nobody can make real-time changes to your site during the migration process, which can cause errors. This is especially useful if you run a WooCommerce store.
  • Disable any firewall and redirection plugins. Such plugins, like caching plugins, can cause issues during migration.
  • Obtain the FTP credentials of your web server from your web host.

How to move WordPress site from subdomain to root using a plugin (List of steps)

Using a migration plugin is the easiest way to move a WordPress site from the subdomain to the main domain. While using a plugin can be pretty straightforward, note that not all plugins are built equal. When it comes to website migration, you want a plugin that is easy to use and which has a high success rate. Migrate Guru is such a plugin. It has a simple, clean UI and gets the job done for you in a few clicks. I’ll be using Migrate Guru to demonstrate the process of moving a WordPress site from a subdomain to the root domain.

  1. Install and activate the Migrate Guru plugin on your subdomain just like you would for any other WordPress website. You’ll be taken to the Migrate Guru page on your WordPress dashboard.
  2. Enter your email address to create an account, agree to the terms & conditions and privacy policy, and then click on Migrate Site.
move WordPress site from subdomain to root using MigrateGuru
  1. You’ll be taken to your Migrate Guru dashboard where you’ll be asked to pick the host you want to migrate to. If your host isn’t listed in the available options, choose FTP. As I said before, Migrate Guru will work regardless of which host you use. All you need are the FTP credentials of your web server.
pick host to migrate to
  1. On the next screen, enter the required details. You can obtain the destination server IP address, FTP username, and FTP password from your web host.
enter FTP details
  1. Click Migrate to continue. On the next screen, you’ll see your source and destination URLs and the progress made in migrating the files and folders.

That’s it! Upon successful migration, you should see a message as follows:

migration completed successfully by migrateguru

Click on Visit Migrated Site and you’ll see that your subdomain has moved to the root domain (the primary domain).

How to manually move WordPress from subdomain to root

Migrate Guru is the safest way to migrate WordPress from the subdomain to the root domain. However, if you don’t want to install yet another plugin on your site, then you might look into carrying out the migration manually. Anyway, I only recommend doing it as a last resort. Before you start, you need to have an FTP client to connect to your site remotely via FTP. I’ll be using the popular client FileZilla to demonstrate the process.

Step 1. Change WordPress and site addresses in the settings

Go to Settings > General in the WordPress dashboard of your subdomain. Change the URL for both the WordPress Address and Site Address to your root domain name. Click on Save Changes at the bottom to save the changes.

changing URL for WordPress address and site address

Step 2. Move WordPress files to the root directory

  1. Connect to your root domain via FileZilla. You can either use Quickconnect or go to File > Site Manager to do so.
connecting to FTP
  1. Enter the subfolder containing the subdomain’s WordPress installation that you want to move from the ‘Remote site’ area of FileZilla.
entering subfolder
  1. Select all the files and directories inside this directory, then drag and drop them to the root directory. This is the public_html directory by default.
moving all the selected files and directories to public_html

FileZilla will now start moving all the WordPress files and folders to your root directory. FTP is awfully slow, so this process will take a lot of time, especially if you have a very large site with a lot of media files.

Step 3. Update the wp-config.php file

WordPress looks up the wp-config.php file to communicate with the database. If it isn’t configured with the correct database information, a visitor won’t be able to access the site. In this step, we’ll update this file to reflect our change of domain name.

In FileZilla, navigate to the root directory of your site. Right-click on the wp-config.php file and click on View/Edit to edit the file. Insert the following lines of code above the comment that says “That’s all, stop editing! Happy publishing.”

define(‘WP_HOME’, ‘http://example.com’);
define(‘WP_SITEURL’, ‘http://example.com’);

Replace ‘example.com’ with your root domain. These lines will tell WordPress that the new domain name for your website is the root domain. Save and close the file, then re-upload it to the site server.

Step 4. Fix permalinks and update internal links in your WordPress settings

Some permalinks on your website may not work properly after the migration. To fix broken permalinks, we have to make some changes:

  1. Log in to the WordPress admin panel of your root domain.
  2. Go to Settings > Permalinks and click on Save Changes. This updates the .htaccess file that controls the permalinks on your site. Any broken permalinks should now be fixed.

Now, the internal links on your website may still point to the old domain, i.e., your subdomain. The best way to fix internal links so that they point to the correct domain name, i.e., the root domain, is to use the Go Live Update URLs plugin. Here are the steps:

  1. Install and activate the plugin on your root domain.
  2. Go to Tools > Go Live from your WordPress admin dashboard.
  1. On the next screen, enter your old and new URLs in their respective fields. The plugin will update all instances of the old URLs in the checked databases. Uncheck any databases that you don’t want to get updated.
  1. Click on Update Urls to finish.

Things to consider when moving WooCommerce from subdomain to root

Migrating a WooCommerce site takes a little more care than the typical site. Since an e-commerce site has transactions taking place in real-time as people make purchases, trying to move it while it’s live can break the site.

If you have a WooCommerce site, put it in maintenance mode first before trying to move it to the root domain. Themeisle’s WP Maintenance Mode & Coming Soon plugin is a really good tool to do so. Maintenance mode essentially “pauses” your site so that nobody can make changes to it. You can disable it once the migration is complete.

Things to consider when moving a multisite from subdomain to root

A multisite is a little more complicated to move since the database has multiple references to the server name and the folder locations. When moving a multisite from a subdomain to the root domain, there are three tables that you need to review to ensure all entries were updated correctly:

  • wp_blogs
  • wp_site
  • wp_x_options

For wp_x_options in particular, look for the following three fields and edit them as needed:

  • home
  • siteurl
  • fileupload_url

Things to do after you transfer WordPress from subdomain to root

Although the migration is technically complete now, there are still some things you need to do to ensure a smooth transition:

  • Needless to say, visit your site at the root domain. Verify that it now shows the contents of what was your subdomain a while ago.
  • Disable maintenance mode if you enabled it before the migration started.
  • Clear all caches of your site. Caches store copies of your site so that it loads faster, but they may store copies of your old site, which could be a problem.
  • Re-enable any plugins you had deactivated before you started.

There’s one more thing you need to take care of. After updating the URLs and internal links in your database, when you now try to visit your subdomain, you’ll get a 404 Error.

While you may leave this page as it is, it’s better to make the subdomain’s URL redirect to your root domain. That way, visitors who aren’t aware of your site migration won’t be affected and will be able to interact with your site as if nothing happened. It’s also good for SEO because you won’t be losing any traffic; any traffic to your old URL will be redirected to your new URL.

First, download and open the .htaccess file from your root directory using FTP. The .htaccess file is a hidden file, so if you don’t see it, you’ll have to enable the option to show hidden files in your FTP client. For FileZilla, you’ll see the option under the Server menu. Next, insert the following lines of code in the file, between the # BEGIN WordPress and # END WordPress comments:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com/subdirectory$
RewriteRule (.*)$ http://www.example.com/$1 [R=301,L]

Replace ‘example.com’ with your root domain name and ‘subdomain’ with the name of the subdomain that you moved. For the RewriteRule line, only put ‘www’ in if your URL actually uses it.

Troubleshooting issues after the migration

While moving a site from a subdomain to the root domain is a simple, straightforward process, you can still face some issues after the migration. I’ll enumerate some of the common ones below, along with how to fix them.

  • HTTP 500 ERROR: Notorious for being hard to diagnose and fix, the HTTP 500 internal server error means the server hosting your site is facing a problem or two, and hence can’t fetch your site. To minimize the chances of encountering this error, disable any firewall and caching plugins before you start. If you’re unfortunate enough to get this error, head on over to our guide for troubleshooting it.
  • Error establishing database connection: This error is usually caused by incorrect credentials in the wp-config.php file. Check that the values for DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, and table_prefix are correct.

Conclusion

Moving a WordPress site from a subdomain to the root domain essentially involves moving all the WordPress files and folders from the subdomain’s folder to the root directory. The process is simple, however, doing it on your own is a significant time sink and is error-prone. It’s why I highly recommend using a plugin, and Migrate Guru in particular, since it’s easy to use, can do the job really quickly, and requires no setup from your end.

Recommended read: How to move WordPress from a subdirectory to root

FAQs

Q – How can I move my site from a subdomain to the root domain?

A – There are two main ways:

  • Use a dedicated migration plugin like Migrate Guru; or
  • Do it yourself (via FTP).

Q – What is the easiest way to move a website from a subdomain to the root domain?

A –  The easiest way is to use a dedicated plugin. We highly recommend Migrate Guru since it’s easy to use, has no downtime, does the job quickly, and works with all the popular web hosts out of the box.

Tags:

You may also like


How to Limit Form Submissions with Droip in WordPress
How to Limit Form Submissions with Droip in WordPress

Forms are an indispensable part of any website because of their versatility, letting you collect information for various purposes! However, people with ill intentions often attempt to exploit these forms…

Manage Multiple WordPress Sites
How To Manage Multiple WordPress sites

Management tools help agencies become well-oiled machines. Each task is completed with the least amount of effort and highest rate of  accuracy.  For people managing multiple WordPress sites, the daily…

PHP 8.3 Support Added to Staging Feature
PHP 8.3 Support Added to Staging Feature

We’ve introduced PHP version 8.3 to our staging sites. Test out new features, code changes, and updates on the latest PHP version without affecting your live website. Update PHP confidently…

How do you update and backup your website?

Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.

Updating Everything Manually?

But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.

Backup Your WordPress Site

Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.