How to Move WordPress From Subdomain to Root Domain

In this tutorial, we will show you how to properly move your WordPress site from a subdomain to the root domain.

1. Backup your WordPress site

Before we start doing anything it is highly recommended to make a complete backup of the WordPress site.

To do this, connect to your server via SSH first.

Next, navigate to the WordPress root directory. For example, it could be located at: /var/www/html/wordpress/.

To make a full archived backup of the entire WordPress site, run the following command:

tar -cpzf wp-backup.tar.gz /var/www/html/wordpress/

Additionally, you will also need to make a backup of your database. The WordPress database stores all the information about the website like posts, pages, comments, user accounts, plugin configurations etc.

To make a full backup of the WordPress database you can use the following command, followed by the database password:

mysqldump -u db_user -p db_name > wp_db_backup.sql

Make sure to change the wp-user and wp-database accordingly with the actual database user and database name.

If you are not sure of the database information that is currently associated with the WordPress site, check the wp-config.php file inside the WordPress root directory and look for the following lines:

define('DB_NAME', 'db_name');
define('DB_USER', 'db_user'); 
define('DB_PASSWORD', 'db_password')

The backup is now complete and you can start with moving your WordPress site from the subdomain to your root domain.

2. Update your site URL

The first thing you need to do before you start moving your WordPress site files is to log in to your WordPress dashboard and change the WordPress address and the Site Address.

Once logged in to the main dashboard, navigate to Administration > Settings > General.

Change the WordPress address (URL) from “http://yourdomain.com/subdomain” to “http://yourdomain.com“.

Change the Site Address (URL) from “http://yourdomain.com/subdomain” to “http://yourdomain.com“.

You can make these changes by editing the wp-config.php file inside your WordPress website directory.

Inside this file add or edit the following lines to:

define('WP_HOME','http://yourdomain.com');
define('WP_SITEURL','http://yourdomain.com');

3. Move the WordPress site files

The next step is to move all of your WordPress files from the subdomain directory to the root directory.

Depending on the directory structure this folder can be named differently. For example, if the files for the WordPress subdomain were located at /home/user/public_html/subdomain we will need to move the files one level above, in the public_html directory at /home/user/public_html. You can do this by using any FTP manager or through the command line with:

mv /home/user/public_html/subdomain /home/user/public_html

Of course, make sure you use the absolute path to your own WordPress installation depending on your own directory structure on your server where your site is located.

That’s it. You should now be able to access your login page and login to your dashboard using the new website URL.

4. Update Permalinks

If you are using Permalinks, ensure that the link structure is the same with the new website URL.

You can find the Permalinks setting page under Administration > Settings > Permalinks.

 

Moving a WordPress website from a subdomain to the root domain is an easy task if you have a Managed Cloud VPS Hosting with us. Feel free to ask our expert Linux Administrators to move the WordPress site from a subdomain to the root domain, and it will be taken care of immediately. They are available 24×7, so you can get the help you need at any time.

PS. Feel free to share this blog post, on How to Move WordPress From Subdomain to Root Domain,  if you liked it by using the social network shortcuts – you can also leave a comment instead, found under the share buttons.

Leave a Comment