Frankly speaking, the subdomain is a perfect way to achieve the staging environment for the development purpose of the website. Search engines will regard the subdomain as a completely independent website. In this case, you can do the development without the worry of influencing your main domain or the live website. Now, when the testing or the developing process is finished, you might be wondering to migrate the subdomain site to the root one. In the following, we’d like to come out the simple steps of how to move WordPress from subdomain to root domain. Note that if your subdomain is alive online for a while, it is important for you to maintain the existing traffic juice.
Before the Migration
In fact, you have two main options to achieve the moving from subdomain to the root domain.
- If you leave the subdomain intact, you can make a backup of the whole site using the WordPress backup plugins and restore the files directly from the subdomain to the main domain. This way, you can leave a WordPress install in your subdomain so as to generate a perpetual staging environment for the testing purpose.
- Or, you can move the WordPress install entirely to your root domain. Surely, you can remove the WordPress install in your subdomain folder. If you want to keep it, you can rewrite the URL to the root folder.
No matter which option you choose, you’d better do the following steps before moving WordPress from your subdomain to the root one. Note that the “root” means the domain root folder but not the hosting root folder. This one typically calls as public_html.
- Make a backup of your WordPress site, for both the subdomain site and the main domain site. If you already schedule the backup process, you can pass this step.
- Make sure that you can access your cPanel File Manager or the FTP client properly.
- Remove everything from the public_html directory. For the successful moving, you have to remove all the files and folders from this special directory, so they will not interfere with your subdomain data. Here, if there are some server related folders like cgi_bin, you can do nothing to them.
- Delete all the cached pages or caching data if you use a caching plugin.
After finishing these steps, you can start moving WordPress from subdomain to root domain now.
Move All the Data and Files from Subdomain to Root Domain
Here, you should use the FTP client and connect to your website. Then, you have to find out the folder of your subdomain to download all the files to your local machine.
And next, you have to navigate to the public_html folder, which is the root folder for your main domain. Now, you simply need to upload all the previously downloaded files into it.
In fact, this step can also be done using the cPanel control that provides the special File Manager. After entering this tool, you firstly need to go to the Settings section to choose the checkbox that allows showing all the hidden files. And then, you can follow the below steps.
- Navigate to the subdirectory or folder that contains all your WordPress information. Here, you can see a list of files and folders from the right hand panel.
- Choose all the listed options and hit the Move or the Copy icon.
- In the new popup, you can decide the destination to move or to copy the information to. Here, you should choose /public_html/. And then, click the Move Files or the Copy Files button.
Now, you can navigate to the root folder to check whether you have moved all the files and folders successfully.
Set Up Website URLs
After the successful data moving, you still cannot access the website admin via the root domain, but the subdomain instead. This requires you to edit the wp-config.php file of your WordPress site and to add the following lines of code.
Note that the “www” prefix can be removed as you like. After updating and uploading this file back to your website, you can login to your admin panel using the main domain name.
Now, in case that there are still some links will point to the subdomain, you’d better install the Velvet Blues Update URLs plugin to update your links. This way, you can fix the issue that some links or references will point to the old subdomain after the moving process.
Here, you simply need to click the Tools > Update URLs button. And then, you can enter the subdomain in the Old URL section and your root domain in the New URL section. As for choosing which URLs to be updated, you can tick the checkboxes of all the options except to the All GUIDs.
Maintain the Traffic Juice
In addition to the entire content of your WordPress site, you also need to redirect the traffic to the root domain. This can be done by editing your .htaccess file with the following newly added code.