If you’re switching to WordPress from a static site, from a site builder provided by your hosting provider, or even from an old WordPress site, you’ll want to ensure that your old site still works while you’re setting up the shiny new WordPress installation.
The good news is that you don’t have to take down your old site while you’re setting up your new WordPress site, nor do you have to redirect your old site somewhere else. And when you’ve finished creating your new WordPress site, you can simply change a few settings and have the new site working on your domain in a matter of minutes. All without having to move either of your sites.
In this tutorial, I’ll show you just how to do this. I’ll show you how to install your new site in a subdomain so that you can work on it without affecting the existing site in your root folder, and then how to switch over to the new site when you’re ready for launch.
What You’ll Need
To follow along with this tutorial, you’ll need these tools:
- An existing site in the root folder of your domain. This could be a static site, a WordPress site, or something else—it doesn’t matter.
- FTP access to your domain.
- A code editor.
If you’re replacing an existing WordPress site and all you want to change is the theme, then you probably don’t need to go so far as to create a new WordPress installation. Instead, use the Theme Test Drive plugin to make your theme visible just to the site admin while you test it. But if you’re making major alterations to the structure, content and functionality as well as the theme, it’s easier to start from scratch with a new installation.
Installing WordPress in a Subdirectory
The first step is to install your new WordPress site in a subdirectory of your root directory.
You can do this using an auto-installer provided by your hosting provider or by downloading and installing WordPress manually. It’s best practice to do this manually as hosting providers have a nasty habit of adding their own code to WordPress when you use an auto-installer.
Once you’ve done this, you’ll have two sites:
- https://domain.com will be your existing site, where ‘domain’ is your existing domain name.
- https://domain.com/new will be the new site, where ‘new’ is the name of the folder where you installed WordPress. You can call this what you want, but it makes sense to use a name that’s meaningful to you and anyone else with FTP access. You don’t want anyone accidentally deleting the folder!
Note: If you have a security plugin installed on the old site, it may warn you that a new folder has been added that’s not part of WordPress core. Ignore this!
Setting Up or Migrating the New Site
Now it’s time to set up your new site. You can either do this using the new live site (making sure you block access to search engines via the Settings screens), or by using a local development site and then uploading that to the remote site.
If you do upload your site from remote to live, you’ll need to edit the database using the full domain of the new site, i.e. https://domain.com/new. If you don’t do this, you won’t be able to test your new site before making it live, as any links will go to the old site. Once you’ve completed the settings for the site and made it live, WordPress will make sure any links resolve correctly to domain.com.
Once you’re happy that the new site is working as it should, it’s time to make it live.
Before You Make the Site Live
Before you edit the settings of your new site to make it live on your domain, you need to empty the cache if there is one.
If your old site runs on WordPress (or another CMS), or if you use caching provided by your hosting provider, disable any caching plugins and empty the cache.
Do the same with your new site—empty the cache for that too.
Important: Now make a backup of both sites and store it away from your remote server. On your local machine or using Dropbox is best.
Changing Settings in the New Site
The next and most important step is to ‘move’ your new site to the root directory.
The reality is that you don’t need to move the site at all. You just need to copy two files, edit one of them, and edit your site settings.
Copying the Files
Using FTP or cPanel File Manager, copy (don’t move) two files from the subdirectory where you have your new WordPress installation to the root directory (i.e. the public_html directory):
- index.php. If your root directory has an existing index.php or index.html file, delete this (making sure you’ve backed it up first).
- .htaccess. If you can’t see this, enable hidden files in cPanel by returning to the cPanel Home screen, clicking on File Manager and ticking the Show Hidden Files checkbox.
Editing the index.php File
Now you need to edit the index.php file in the root directory—the one you just copied across. Find this line:
require('./wp-blog-header.php');
Change it to:
require('./new/wp-blog-header.php');
Replace ‘new’ in my example with the name of the subdirectory where you’ve installed WordPress for your new site.
Now save the file and close it.
Editing Site Settings
The final step is done in the WordPress admin for the new site.
Go to Settings > General.
In the Site Address (URL) field, type the name of your domain (i.e. delete the subdirectory). Leave the WordPress Address (URL) field as it is.
Click the Save Changes button.
You’ll probably need to log in to your site again as any cookies storing your login credentials for the subdirectory won’t work for the root directory.
Go to Settings > Reading and uncheck the Search Engine Visibility box. Save your changes.
Now refresh the site and test it. It should be working as if it’s installed in the root directory.
Cleaning Up Your Root Directory
Now you have your new site up and running, it’s time to clean up your root directory.
Remove any files relating to the old site. Instead of deleting them, I suggest moving them to another folder (maybe called backup). Or make a copy on your local machine.
Check your file structure in the root directory. Make sure there are no folders or files in there that correspond to slugs in your new site. For example, make sure there isn’t a file called blog if you have a page with the slug /blog in your new site.
This stage is a process of cleaning up your root directory and doing some housekeeping. It’s good practice to remove anything that isn’t needed anymore.
Creating a New Site and Migrating It to the Root Directory Is Simpler Than You Might Expect
If you’ve followed these steps, you’ll know that this is a process that takes no more than five minutes and is very simple.
Being able to create a new site in a subdirectory has many advantages. And instead of having to migrate WordPress from the subdirectory to the root directory, this gives you a quick and easy process to make your new site live.