In the first article I showed you how to get a backup on your harddrive from a site you can’t access anymore due to letting the domain name expire. In this article, I’m going to show you how to keep the files and database on your hosting and recreate the site in a subfolder of the rootdomain that is linked to your hosting account. However, before we make any changes, follow the steps in the previous article so you have a backup of the old version on your harddrive in case anything goes wrong.
1. Rename the subfolder to the name you want to use
When you added an addon domain, a folder was created with the name of your addon domain. For this example, that folder is named “wpprofitperformance.com”. If we keep the folder name as it is now, our new site would have a URL that looks like this http://yourdomain.com/wpprofitperformance.com. I don’t want to have that second .com at the end of the domain, so I’ll be removing that. If you want, you can rename the folder completely if you want to do so.
When you are in your cPanel, go to your File Manager and look for the folder you want to rename. Make sure it’s selected and then click the Rename button at the top of your screen. Change the name to whatever you have decided on and save your changes.
2. Change your site links to the new link structure
Now comes the hard part, you need to mess around in your database to change all the old links to the new link so your site will work in the subdirectory it is in now. Make sure you know what the name of the database is that you’re working in, if not, find that information in your wp-config file first.
In your cPanel, go to your phpMyadmin and find the database linked to your old blog. When you found it, click on it and open it so you can see the database table structure. At the top of your screen you’ll find different tabs, select the one called SQL
You will be brought to a screen where you can insert SQL queries.
Now enter the following queries one by one and click go for each. Don’t forget to change http://www.old-domain.com and http://www.new-domain.com by your old domain name and new one respectively. Also, if you changed the default table prefix (e.g. “wp_”) to something else, make sure to update it in the queries below.
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.old-domain.com', 'http://www.new-domain.com');
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
That’s all there is to it. Some plugins need the site URI. You might need to update that as well. The easiest way to check if another table contains the old domain name is to do a search in PhpMyAdmin (your database -> Search tab -> Select all the tables). It will return all the tables that contain the old site URI and you can then change accordingly as explained above.