How to move WordPress from subdomain to root domain?

When you first install WordPress, you can choose a root domain (http://www.yoursite.com) or subdomain (http://blog.yoursite.com) to host the platform. Should you subsequently decide to make a change, follow these steps to move WordPress from a subdomain to a root domain.

As you’ll be making significant changes to your WordPress configuration, you should first take a backup of your WordPress site. There are various plugins you can use to back up your WordPress files and database but the cPanel Backup Tool, is simple and comprehensive. 

With your site safely backed up, open your cPanel account and select Files > cPanel File Manager.

Navigate to your WordPress root folder and download all files and folders to your local computer. A convenient way to do so is to highlight all of the files and folders, then select Compress from the cPanel File Manager command bar. Then download the compressed archive file that is created. Alternatively, you can highlight your files and use the Download command.

Now navigate to your domain root folder – this will be called public_html. Upload your WordPress site files from your local PC to this folder.

With the site files relocated, you can now amend your WordPress site configuration. Highlight wp-config.php and select Edit from the command bar.

Add the following lines to wp-config.php just before the line that reads /* That’s all, stop editing! Happy blogging. */

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

Change mysite.com to your root domain.

ave the file and close the cPanel File Manager editor. You should now be able to access the WordPress administration dashboard via your root domain.

The next step is to update any links that are pointing to your subdomain so that they now point to the root domain. The simplest way to update your URLs is with a plugin called Velvet Blues Update URLs.

In the WordPress admin dashboard, head to Plugins > Add New, then search for Velvet Blues Update URLs. Install, then activate the plugin.

Select Tools > Update URLs from the WordPress sidebar. Enter your old (subdomain) and new (root domain) URLs and in Step 2, check all options except Update All GUIDs.

Click the Update URLs Now button to proceed.

The final step is to route all traffic that visits your subdomain to your root domain. We do this by editing your site’s .htaccess file. Head back to cPanel File Manager and, at the top right of the screen, click the Settings button.

.htaccess files are hidden from view by default. To expose them, ensure Show Hidden Files (dotfiles) is checked in the Preferences panel, then click Save.

Navigate to your subdomain folder. If you see an existing .htaccess file, delete it, then create a new .htaccess file by selecting + File.

Select the new file and click Edit in the command bar. Enter the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} 
 ^yoursubdomain\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ "http://www.yoursite.com/$1" [R=301,L]
</IfModule>

Remember to use your own subdomain and domain names in the code. Save the .htaccess file and close cPanel File Manager to complete the changeover.

Was this answer helpful? 0 Users Found This Useful (0 Votes)