SWEET PACKAGE DEAL: Get all 12 themes 75% off! See Details

How to Swap a Root WordPress Installation with a Subdirectory WordPress Installation (While Keeping Both)


Last updated on May 13, 2017 No Comments


A WordPress Development Environment Idea for Major Overhauls on Active Websites

If you work with WordPress, you’ve probably needed to redesign a WordPress website at one point or another. Sometimes that can be pretty straightforward. If the website is small without much traffic, you might be able to get away with putting up a temporary splash page while you switch to a new theme and make minor updates.

But in other cases, you might need to do a much more complicated website overhaul. If you’re tasked with major updates to an active website that can’t be taken offline (because that will result in a loss of revenue, orders, or leads), you can’t just start swapping out themes and making other changes willy-nilly. You need a WordPress development environment where you can create the new version of the website separately from the old one that’s currently online. Then, you’ll need to launch that new website, replacing the old one with the new one.

 

Development Options

This entire development idea makes a few assumptions that you’re working within a given scenario:

There are two main development scenarios that I’ve used. I don’t know how commonplace these are, but I think they’re probably the methods other WordPress developers would use as well. (But who knows, I’m not the world’s top authority on anything.)

 

Option 1: Develop Locally & Publish Later

In this case, you’d install WordPress on your computer and develop the new version of the website offline. Later, you would publish it where your website currently lives.

That might look like this:

  1. Install WordPress on your computer with XAMPP. Here’s a great tutorial.
  2. Import all of the content from the current website into your local WordPress.
  3. Make all the changes you want.
  4. Clone your local WordPress installation and database back to the online website location. Here’s a guide that could help you do that.

Pros:

Cons:

 

Option 2: Develop in an Additional WordPress Installation & Later Replace the Current Website

Let’s say you’ve got an active website at example.com. You could install another copy of WordPress in a subdomain or a subdirectory. Say, at example.com/wp/. Once you do that, you can develop an entirely new site on the same server where your current website lives, and you can later point that version of WordPress to your root directory so it replaces the old website.

That would generally be done like this:

  1. Create a subdirectory called /wp/
  2. Install WordPress in it normally.
  3. Develop the new version of your website.
  4. Once the new website is ready, point the WordPress that lives in /wp/ to the root, effectively replacing the old website that lives in the root directory. You don’t even have to delete WordPress from that root.

Pros:

Cons:

I’ve done this with two huge website re-build projects. I like this method because I can get a new, fully functioning website developed online and then I can just swap it out for the old website. For the rest of this article, I’ll tell you how I did it.

 

How to Develop a New WordPress Site in a Subdirectory and Then Point it at the Root

The following is the general process that you could perform to achieve Option 2 from above.

Don’t take any of this as some kind of WordPress gospel. I am largely a self-taught person, and I figure out what I want to do through research and trial-and-error. This method might not be the best solution for you.

 

1. Install WordPress in Your Subdirectory

Go through the same process that you would if you were installing WordPress into your root directory.

  1. Create the directory
  2. Install WordPress in it following the usual instructions
  3. Update your robots.txt file to disallow indexing of this site for now. Add a line that says Disallow: /wp/

2. Import Content from the Current/Old Website

  1. On your current website (which we might as well start calling your “old” website) in the root directory, login to WordPress and export all of your content.
  2. On your new website (in the /wp/ subdirectory), login to WordPress and import all of the content.

No need to mess around with the database here. You’ve already moved over everything.

3. Develop Your New Site

Now, do whatever you want to do in regards to developing your new website.

4. Launch! Point Your Subdirectory WordPress to the Root

This is the interesting part. It’s easy enough to find instructions on how to give WordPress its own directory, but I couldn’t find any instructions on what to do if you already had WordPress installed in the root directory.

Here’s what you do:

(First, make backups of everything.)

  1. Login to WordPress in your subdirectory (at example.com/wp/)
  2. Go to Settings > General
  3. Change the Site Address (URL) setting to where you want the website to display (example.com, in this case). Leave the WordPress Address (URL) as it is. Click Save.
  4. You’ll see a 404 error on the front end now. That’s normal.
  5. Go to your root folder and edit the index.php file. Change this line: require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ ); To this: require( dirname( __FILE__ ) . ‘/wp/wp-blog-header.php’ );
  6. Remember to update your robots.txt file so that you don’t continue blocking crawler access to the website.

Step 5 is the key. It tells WordPress to look to your subdirectory for how to display your entire website. Even though your old WordPress installation still exists in your root directory, it’s completely ignored since you’ve told WordPress to look at your subdirectory instead.

You do not have to edit your .htaccess file. If you were only installing WordPress in a subdirectory, and there was no WordPress installation ever in your root, then you would have to copy the .htaccess file from your subdirectory to your root. However, you already have an .htaccess file there, and there should be no reason to move or edit it.

I hope all of that made sense! It took me a while to figure out this process on my own. I hope it will help someone else.

 

wordpress themesReady for a New Theme?

Shop Themes to find a modern, responsive theme that's easy to use and helps you accomplish your goals.


Posted in Development, WordPress Tips. Tagged with: , , ,


Leave a Reply

Your email address will not be published. Required fields are marked *