Migrate Sub Domain From Multi Site Network To Single Installation

This tutorial provides the step by step instructions for moving a sub site from Multisite ( MS ) network to its own domain on its own standalone WordPress installation.

In this example, we’ll move sub.example.com to example.com in 5 steps.

Step 1 : Login to the sub site and go to Tools > Export all content like this:

Step 2 : Install WordPress on its own domain.

Here’s 2 video tutorials showing you how to install WordPress.

Step 3 : In the Dashboard of your new WordPress installation, go to Settings > Permalinks and make sure you use exactly the same permalink structure as you are on your MS sub site.

Step 3 : Go to Tools > Import and import the XML file you exported in step 1 using the WordPress importer which you’ll need to install first and then run. Make sure you also import attachments like this:

Step 4 : You’ll also need to redirect links from your old sub domain to your new self hosted top level domain. Add the following directives in .htaccess file of the network admins WordPress installation:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

In the above code, we redirect sub.example.com to http://example.com.

Step 5 : Go to My Sites > Network Admin > Sites and deactivate the sub site you have migrated.

Trouble Shooting Broken Links

After completing a recent migration using this method, i discovered multiple problems with image links. For some reason, the links where using sites/4 like this example http://sub.example.com/wp-content/uploads/sites/4/2014/12/image.jpg

I used the Velvet Blues URL’s plugin to change all the links from sub.example.com to example.com which resulted in the following: http://example.com/wp-content/uploads/sites/4/2014/12/image.jpg

This URL clearly won’t work on the single installation as the installation does NOT include a folder named sites and a folder named 4. In this case, rather than play around with SQL database queries to remove sites/4/ from all URL’s, i modified them manually.

Another method i could have used if the site contained a large amount of images would have been to create 2 new folders in the uploads folder to match the path to the images used on the MS installation.

After a previous migration, i also used the Search & Replace plugin to fix broken image links which worked very well.

Options Considered But Not Tried

I also looked at purchasing the Developer license for the WP Migrate DB plugin which includes addon support for Multisite migrations.

Run SQL Database Query in phpMyAdmin

Note: You can find the name of your database in your wp-config.php file around line 23 which is located in the root directory of your WordPress installation. It looks like this: define( ‘DB_NAME’, ‘wp_123’ );

After selecting the database on your new single installation, you can run a SQL query in phpMyAdmin to update URL’s which gives you another way of fixing broken image links. Go to the SQL tab and enter the following code replacing the URL’s you want to change.

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://sub.example.com/wp-content/uploads/sites/4','http://example.com/wp-content/uploads');

And replace the attachment URL also:

UPDATE wp_posts SET  guid = REPLACE (guid, 'http://sub.example.com/wp-content/uploads/sites/4', 'http://example.com/wp-content/uploads') WHERE post_type = 'attachment';

You could also try changing the links using a SQL query on the database of your single site installation.

Search Find & Replace Broken Image Links

Another solution is a search find and replace in phpMyAdmin.

From the “Search” tab, click the “Find and replace” second level tab:

Find and replace dialog

Enter the text you want to find and what you want to replace it with. In this case; we want to find /sites and remove it entirely (or, rather, replace it with nothing). You also have to select the column to search from the dropdown:

Find and replace fields

Once you click “Go” you’ll see a preview of all the changes about to be made. Verify that you’re not inadvertently changing something like http://local.dev/site/newpage or http://local.dev/wp-content/uploads/sites/4/2000/05/site.png where the search term is accidentally in another portion of the search term.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.