A lot of people start websites in a subdomain only to move it later to the root. This process isn’t overly difficult, but it can be time consuming. However, it’s a good way to move the site from something like, «website.yourdomain.com» to simply, «yourdomain.com.»
Subdomains are useful if you want to expand what the main domain offers. For example, some people will use subdomains for blogs and the main root website as eCommerce.
In this tutorial, I’m going to show you how to move WordPress from its subdomain to a root domain. It’s as easy as copying the files over and making a few minor adjustments.
Create a Backup of Your Site
Before doing anything, make a backup of your website. This helps protect you from problems that may arise by giving you a quick method to recover. You don’t want to be in the middle of a file transfer and discover something was corrupted and irreparable.
You have many ways to create this backup whether you’re using FTP, plugins, Softaculous or copying files yourself. Perhaps the easiest method is by using WordPress backup plugins. Some will even save to your cloud storage services like Dropbox.
Collecting Your Subdomain Files
You have a couple of options when it comes to grabbing your website’s files from the subdomain. Many people prefer FTP programs like FileZilla as it offers a lot of control over the site as a whole. For this tutorial, I’m going to use File Manager in cPanel.
From your cPanel dashboard, click «File Manager» from the Files section.
Click the «public_html» folder from the left column. Technically, this is your root folder for your domain.
The root directory will have your subdomains listed inside it. It may also have files inside such as «htaccess» or «index» if you’ve ever used it for hosting a website. Take note, many of these files are going to be deleted. If there are files you want to keep, I suggest copying them somewhere.
Access the subdomain you’re going to move by double clicking into it.
Click the «Select All» option from the tool bar.
Click the «Compress» tool from the top bar.
Choose to create a Zip Archive.
Scroll down the Compress window and change the filename. As you see on my screen, it wants to create «cgi-bin.zip.» This is because the cgi-bin folder was the first in the list of selected files and folders. Change this name to something you’ll recognize ending with «.zip.».
Click the «Compress File(s)» button from the bottom. Coincidentally, this is also an easy way to create a backup of your site files.
After a moment, the result screen will appear. Click the «Close» button to return to File Manager.
Select the ZIP file and click the «Move» tool.
In the Move window, delete everything after the «public_html/» text. This tells File Manager you want to move the ZIP file to the root directory.
Click the «Move File(s)» button.
Go back to your root folder. Select the ZIP file and click «Extract» from the tool bar.
Click the «Extract File(s)» button.
Congratulations! You just moved WordPress from a subdirectory into the main domain.
Before you close out of File Manager, we need to make sure WordPress knows the new URL exists. This is done by adding a couple lines to the wp-config.php file. This file holds site specific information such as the connection to the database.
Select the wp-config.php file and click, «Edit.»
Click the «Edit» button from the window. This is just telling us we’re going to use TUF-8 encoding, which is something we don’t need to worry about at the moment.
Scroll down to the bottom of the file. Input this code just before, «That’s all, stop editing! Happy blogging.»:
[ht_message mstyle=»info» title=»» show_icon=»» id=»» class=»» style=»» ]define(‘WP_HOME’,’https://yourdomain.com’);
Make sure you change the «yourdomain.com» section to reflect your own website URL.
Until search engines get your new URL crawled completely, you’ll need to redirect traffic. This is done by logging into your subdomain site and installing plugins like Redirection.
Without redirects, visitors and search engines will still go to your subdomain website instead. There are many redirect plugins to choose from, so you’ll have to find one you’re comfortable with. I suggest using Redirection as we’ve used it to cover creating redirections in the past and it works well.
A redirect not only works to help visitor traffic reach your new URL, but search engine bots as well. It helps guide SEO and improves performance by letting sites like Google know your content has moved.
Changing URL Settings
After the move, a lot of internal links and resources will have to be fixed. This is because they will be still pointing to the subdomain instead. To fix this, we’re going to use Velvet Blues Update URLs. This plugin will go through and automatically change all links from one URL to another.
For this next part, you will need to install and activate the Velvet Blues Update URLs plugin from your new website location. Meaning, you will need to access your website from the root domain address instead of your old subdomain.
Go to the Tools section and click, «Update URLs.»
Input your old URL address information. This will be the «https://youroldsite.yourdomain.com» address.
Input your new URL address information. This is the root domain URL, which may be something like: «https://wwww.yourdomain.com.»
Select where you want the URLs to change and click, «Update URLs Now.» Since this is a complete move of the website, I would suggest all except for the GUID at the bottom.
Don’t Forget to Change Search Console Properties
Search Console is part of Google Webmaster Tools. It’s the first step to making sure your content is seen by the massive search engine. Plus, it has a lot of features to help you develop strategies for future content.
Once you move the site, don’t forget to add your site’s information to Search Console. This includes any sitemaps you create for the new location, which should be done immediately if you want search engines to identify the new location correctly.
What About External Resources?
Many people will have things like social media accounts linking back to the website. You should go through and change all of these to reflect the new URL. Although the redirect will help traffic find your pages, it’s better to just fix these now. After all, you might want to delete the subdomain at some point down the road.
Email addresses, forms, business cards and more should also be considered if you used your site on anything else. Moving WordPress from a subdomain to a main domain entails making sure all of your external properties are changed.
Moving is Time-Consuming
As you can see, it’s not all that difficult to change WordPress directories. It just takes a lot of time when you consider how many things you may have to alter to reflect the new URL. However, the ends justify the means as it will make the site more efficient.
How often do you use subdomains when developing a website? Have you ever moved a WordPress site before?