Moving a WordPress Site from a Subdirectory to the Root

This is a straightforward method that will allow you to keep your WordPress install in a subdirectory and use your root domain’s URL.

1. Back Up Your Site

It’s a good idea to have a backup, just in case anything goes wrong. This includes your theme files, plugins, any media and your database.

You can use any back up tool you feel most comfortable with. You may choose to copy your files to your computer manually using FTP or SFTP with FileZilla, a backup plugin like WordPress Backup to Dropbox or a third-party service like VaultPress.

You’ll need to ensure you copy any hidden files like .htaccess.

2. Delete Any Existing Site

If there’s an existing site in the root directory, you’ll need to remove it. If you want to keep a copy, now is the time to back it up.

If you have access to Softalucous in your site’s cPanel, you can easily uninstall WordPress from the root directory.

Otherwise, login to phpMyAdmin and drop the database. Then delete all WordPress files.

3. Turn Off Pretty Permalinks

Turn off pretty permalinks while making other changes.

Login to your site and go to Settings > Permalinksand turn off pretty permalinks by selecting the “Default” setting. Save changes.

4. Change Your Site Address

Go to Settings > General and change the address of your site, but not the address of WordPress. So if your site is, change your settings to the following:

Save your changes, but don’t refresh your site just yet.

5. Copy and Edit Files

Login to your site using cPanel or FTP/SFTP and download two files to your computer:

  • index.php
  • .htaccess – only if you have one. If you don’t, there’s no need to create one.

Open index.php. Look for the following line:

require ('./wp-blog-header.php)

And replace it with this:

require ('./subdirectoryname/wp-blog-header.php)

So for our site, we would change the line to:

require ('./test/wp-blog-header.php)

Save index.php. Now, upload both index.php and .htaccess to the root directory of your site.

6. Turn On Pretty Permalinks

Go back to Settings > Permalinks and turn pretty permalinks back on again with the settings you need for your site.

7. Test Your Site

When you enter the root domain of your site into your browser, the WordPress install in your subdirectory will display, but with the root URL.

And that’s all you need to do to!

Moving a WordPress Website Between Hosts

This is a bit trickier than moving your site from a subdirectory to the root directory. This time we’ll actually need to move some files around.

1. Back Up Your Site


FileZilla is my FTP program of choice.

Rather than back up your site in case anything goes awry, you will need to back up files so we can copy them to the new server.

For this step, it’s best to use FTP/SFTP and do things manually. Connect to your old site and copy all of your files to a folder on your computer. Don’t forget to include any hidden files like .htaccess.

2. Export Database

Login to your site’s cPanel and go to phpMyAdmin. Select the database for your WordPress site and then click “Export” at the top of the page.

Leave the default “Quick” option selected and click “Go” to download the database to your computer.

3. Create WordPress Database On New Host Server

The next step is to create a database on the new server for your WordPress site.

In cPanel, go to MySQL Databases and:

  • Create a new database.
  • Create a new MySQL user.
  • Add user to the new database and grant “All Privileges”.

Don’t forget to write down the database name, username and password for later.

4. Edit wp-config.php

Since the database information will be different on the new server, we need to update our site’s wp-config.phpfile with the new details.

Amongst the files in your WordPress install, which you downloaded earlier, you’ll find a wp-config.php file. Make a copy of this file and rename it wp-config-old.php and save it elsewhere on your computer. This is just in case you make a mistake and need to restore the file.

Open the original file. You will need to update the database name, database username and database password so grab those details from the previous step.

Find the line:

define('DB_NAME', 'db_name');

The db_name part of this line will be the new name of your database. Replace this with the name of the database you created earlier.

Next, find:

define('DB_USER', 'db_user');

Change the db_user part of this line to the username you created.

Lastly, track down:

define('DB_PASSWORD', 'db_password');

Replace db_password with the password you created.

Save wp-config.php and close it.

5. Import Database

Now that the database is up and running, we need to import the .SQL file we exported earlier.

Open phpMyAdmin in cPanel and select your new database. Click the “Import” tab at the top of the page

Under “File to Import”, select the database file you downloaded earlier.

In the “Partial Import” section, un-check “Allow the interruption of an import in case the script detects it is close to the PHP timeout limit” and then click “Go.” After a little while, depending on the size of your file, you’ll get a confirmation message that the file has been successfully imported.

Import database

Import the database from your old server and get ready to use your site with your new host.

6. Upload WordPress Files to New Server

We’re almost there. The next step is to upload your site to your new host.

Login to your site using FTP/SFTP and navigate to where you want to copy across your site. If you want your site in the root directory of your site’s domain, then copy your files to the public_html folder.

Leave the copy of your site on your computer for the time being so you’ve got a backup.

7. Edit Database

In order for images and posts linking to other parts of your site to work, you’ll need to update your domain name in your database.

It’s no good just opening up your database and updating it manually because you’ll break any serialized data. A great script for this is Search Replace DB. This script preserves serialized PHP strings when performing a search and replace.

To use the script, upload it to your site, scan all the tables and then input what you want to find (your old domain name) and replace (your new domain name).

8. Configure DNS Settings

Before your site will work with your domain name, you will need to reconfigure your domain’s DNS settings. You will need to login to the site hosting your domain and point your domain to your new web host.

This step is different for every web host, so it’s best that you contact your host if you’re not sure what to do.

9. Enjoy Your New Host

After your DNS changes have fully propagated (this can take up to 48 hours), you will be able to login to your WordPress site on your new server with the username and password you used on your old server.