How to Move WordPress From Subdomain to Root

Share on facebook
Share on twitter
Share on email

Do you have a subdomain you want to move to the root or main domain? This guide can help. It shows how to move WordPress from subdomain to root the proper way. The “proper way” means all your WordPress posts and pages keep their SEO rankings after the move.

Best of all, the process is straightforward when you follow the simple steps on this page. That’s because moving files from a subdomain to the root is carried out on the same hosting account.

Why Move a WP Subdomain to the Root?

Jump to the tutorial if you know the difference between root and subdomains and why you’re making the move. If someone else has suggested you migrate your subdomain to the root—but you’re not sure why—keep reading. A little knowledge is useful for understanding how to do something and the reasons why. It also makes you a better webmaster.

Site owners sometimes end up focusing on the subdomain more than the root domain. They may decide to bring all the content from the subdomain into the root directory. Some users set up a new WordPress install as a subdomain and later want the content as part of the root domain.

WordPress subdomain Vs. root domain

Your root domain is also known as a primary or main domain. In simplistic terms, it’s the name of your website, e.g., mysite.com. Add www. or https:// to the front of your domain name gives you the site’s Uniform Resource Locator (URL), which is your web address.

A subdomain is a division of your main domain that acts as an independent site within a site. It lets you set up a separate website without needing to register a new domain. With the latter, you’d have all the hassle of setting up and maintaining an unconnected website.

Subdomain hierarchy

Let’s say you have a practical photography blog where you share photos, tips, and techniques. You might also want to sell cameras and photographic equipment. It’s related to photography, but selling stuff doesn’t fit in with the blog content. Thus, it makes sense to separate product sales from the main site. In this case, your subdomain could be store.mysite.com.

Your photography store has a unique identity and content specific to the sale of equipment. A subdomain needs to be extensive enough to warrant a separate area. Google uses subdomains—rather than subfolders—to redirect users to specific areas. One example is the support subdomain, i.e., https://support.google.com/ and not https://google.com/support.

Subdomain to Root Domain Tutorial

Follow this tutorial once you’re sure you want to move the subdomain to the root. Before you begin, it’s vital to make a complete backup of your WordPress website. A full backup means all your WP files and folders and the database. It’s also wise to save the backup locally to your computer, a removable drive, or both.

With the site backed up, let’s move your subdomain over to the root directory.

Moving WP Files from Subdomain to Root

You can use a standalone FTP client for the file migration procedure or File Manager in cPanel. This tutorial illustrates with cPanel as every hosting account has one.

Read cPanel for beginners first if you’re new to this popular control panel.

Log in to your website’s cPanel account.

Click File Manager (first icon) in the FILES section.

File Manager opens in a new browser tab and leaves cPanel open.

Click the public_html (root) folder in the left column, then:

  1. Locate and select your subdomain folder

All subdomain files and folders on the web server load in the File Listing window (right).

  1. Click the Select All link from the File Manager toolbar
  2. Click the Compress link from the top menu bar

The Compress Files option box appears.

Select the Zip Archive radio button.

Replace the /file name at the end (excluding .zip) with something meaningful.

Click the Compress File(s) button.

You’ll get a confirmation message once all files and folders are compressed.

Click the Close button.

Point to note: Zipping files & folders copies them, leaving the originals where they are.

  1. Click your new zip file in the File Listing section (right).
  2. Click the Move link from the top menu bar.

The Move window appears with the current file path in its ‘move this file to’ field.

  1. Replace the current file path with /public_html/

This tells File Manager to move your subdomain zip file to your WordPress root folder.

  1. Click Move File(s).

Your zipped file is now in your WordPress public_html root directory.

  1. Click the public_html folder from the Directory Listing area (left)
  2. Click to select your zip file from the File Listing area (right)
  3. Click the Extract link from the top bar

Congratulations! You have successfully moved WordPress from a subdomain to the root. However, there’s still a couple of things we must do to inform WordPress of the move.

  1. Right-click on the wp-config.php file in the File Listing area (right)
  2. Select Edit from the pop-up menu.

Your wp-config.php file opens in a new browser tab.

Replace yourdomain.com with the name of your website in the code snippets below.

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

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

  1. Copy then paste the code above to the bottom of your wp-config.php file
  2. Click Save Changes
  3. Click Close to exit the editor

You can leave File Manager open as we’re going to need it again soon.

Update URLs, Redirect Files

PLEASE BACKUP YOUR SITE AND DATABASE BEFORE CONTINUING

Your WordPress database still holds links that point to subdomain files that are no longer valid. To fix this issue, we need to update your URLs by redirecting files. Fortunately, there’s a plugin called Velvet Blues Update URLs that makes this final step quick and easy.

See How to Install and Activate WP Plugins if you’re new to WordPress.

Install and Activate Velvet Blues Update URLs from your WordPress admin area.

Next, go to Tools => Update URLs from the Dashboard side menu.

You’re now at the Velvet Blues Update URLs screen.

  1. Enter your subdomain URL in the Old URL (Old Site Address) field
  2. Enter your primary (root) domain in the New URL field

The final step is to choose which URLs you want the plugin to update.

Tick (check) all the options, excluding All GUIDs’

Click Update URLs NOW

The update process could take a while with larger sites. The plugin will display a confirmation message after successfully updating your URLs.

Redirect Subdomain Traffic to the Primary Domain

It’s vital to keep site visitors and the search engines in the loop. Let’s redirect any subdomain traffic to your primary (root) domain. The way to do this is to add specific code to a new .htaccess file (pronounced dot aitch tee access). This file needs to be in the subdomain folder.

Head back to cPanel and open File Manager from the FILES section. Alternatively, use an FTP client to edit this file if you prefer.

Click your subdomain folder and look for the .htaccess file. Read ‘unhiding hidden files’ in the next section if you don’t see it. If you do see the file, delete it and skip to ‘Create a new .htaccess.’

Unhiding hidden WordPress files

If your .htaccess is hidden from view, we need to unhide it so you can delete it.

Click Settings on the top right of File Manager.

In the Preferences pop-up, put a tick in the box next to Show Hidden Files (dotfiles).

Click Save to close the Preferences box.

Your .htaccess file should now be visible. If it is, delete it. If you still don’t see it, then you don’t have one. In either case, you can move to the next step.

Create a new .htaccess file

Click the File link from the top menu bar in File Manager.

Now type .htaccess into the New File Name field.

Check that the URL is correct in the ‘New file will be created in’ field.

Click Create New File.

The code below is for your new .htaccess file, but we need to make some changes first.

Replace yoursubdomain with your site’s subdomain name.

Replace example.com with your site’s domain name.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$ [NC]

RewriteRule ^(.*)$ “http://example.com/$1″ [R=301,L]

</IfModule>

Copy the modified code to the clipboard.

Right-click on your new .htaccess file and select Edit from the pop-up menu.

The file opens in Edit view in a new browser tab.

  1. Paste the copied code into your new .htaccess file
  2. Click Save Changes
  3. Click Close to exit the editor tab

You’ve now moved your WordPress site from its subdomain to the primary (root) domain.

Share on facebook
Share on twitter
Share on email

Subscribe to my newsletter

Subscribers to my newsletter get all the latest news, reviews, advice and gossip in the world of search engines, internet marketing, self-publishing, and North Wales (where I live). You can sign up for my free newsletter by clicking this link.

My Books

I have a range of webmaster related books for sale on Amazon in both Kindle and Paperback formats. WordPress, SEO & Self-Publishing.
On Amazon

My Online Courses

My courses cover a range of webmaster related skills, from learning WordPress itself, to installing an SSL certificate on your site.
On Udemy

Comments

Hello, I'm
Andy Williams!

You can get up to 90% off my Online Courses for webmasters, marketers & affiliates (plus a free course on Gutenberg).

Get my newsletter
delivered to your inbox

18748

We respect your privacy

18749