Moving A Website From A Subdirectory To The Root
This is by far the simplest of the three moves I’m going to cover, because you don’t actually have to move anything — or nearly anything. This method will work on a standard installation of WordPress, and will work with most frameworks, or if you’re using a parent and child theme structure.
Beware! This method will not work for multisite installations, just for standard single-site installations.
The great thing about this method is that it only takes from three to ten minutes depending on your setup — no time at all in the scheme of things.
1. REMOVE THE EXISTING WEBSITE
If there is an existing website in the root directory, remove it. It may be another WordPress installation or it may be a static website.
If it’s a WordPress website, make a backup as detailed above, and then delete all of the WordPress files in the root.
- If you have access to Softaculous or another installation service via your hosting control panel, use that to uninstall WordPress.
- If not, use phpMyAdmin to drop (delete) the database from the existing website. See the next section for details of how to do this.
- After dropping the database, remove all WordPress files. This normally means any files or folders beginning with
wp-
. - Beware — don’t remove the existing site until you have made a backup!
2. TURN OFF PERMALINKS
Turn off pretty permalinks in the “Permalinks” screen, which you’ll find in the “Settings” menu. Do this by selecting the “Default” option and clicking “Save Changes.”
3. CHANGE YOUR WEBSITE ADDRESS
In “Settings” → “General,” change the address of your website but not the address of WordPress. For example if you’ve been working on the website at example.com/development
, change the settings as follows:
- WordPress address (URL):
http://example.com/development
- Site Address (URL):
http://example.com
Save by clicking on the “Save Changes” button and move on to the next steps before trying to access your website.
4. COPY AND EDIT TWO FILES
Using FTP/SFTP or cPanel file manager, copy (don’t move) the following files from your WordPress directory to the root directory:
index.php
.htaccess
, if you have one. If there isn’t an.htaccess
file (and turning off pretty permalinks means you’re less likely to have one), don’t worry about creating one.
Edit the index.php
file that you’ve moved. You could do this by:
- Editing it in situ after the move, by using FTP/SFTP or cPanel file manager;
- Downloading it from the subdirectory, editing it and then uploading it to the root directory — instead of making a copy.
The edit you need to make is very simple, to one line at the end of the file. You simply change this:
1 |
require ('./wp-blog-header.php) |
..to this:
1 |
require ('./subdirectoryname/wp-blog-header.php) |
So if you’ve been developing in example.com/development
, just change the line to:
1 |
require ('./development/wp-blog-header.php) |
Save the new index.php
file.
5. TURN PERMALINKS BACK ON AND TEST
Back in the WordPress admin, turn pretty permalinks on again, with whatever setting you need for your website.
Visit the root domain of your website in the browser and it will display the website that’s stored in the subdirectory, but the URL will show the root URL rather than the subdirectory URL. And that’s it!
Uploading A WordPress Website From A Local To A Remote Installation
This is one of the most common instances of moving WordPress. If you’re working on a local website for development and need to upload it either to go live or because you need to show a client or other team members your work, you’re going to need to upload your WordPress website. This is more complicated than moving from a subdirectory to the root directory, and involves moving three things:
- WordPress itself — you’ll need to install this in the new location;
- The database — which you can move using phpMyAdmin;
- Your theme files, uploads and plugins.
1. TURN OFF PERMALINKS
Turn off pretty permalinks in the “Permalinks” screen, which you’ll find in the “Settings” menu. Do this by selecting the “Default” option and clicking “Save Changes.”
2. BACKUP THE DATABASE
Make a copy of the database and give it a new name (for example, by adding “old” to its name).
3. INSTALL WORDPRESS IN THE NEW LOCATION AND UPLOAD CONTENT
Using your preferred method, install WordPress on the server you want to move your website to.
Using FTP or SFTP, copy the files from your local “wp-content” directory to the remote “wp-content” directory, using the same folder structure as in your local install.
Go and have a cup of coffee. These files could take a while to upload.
4. EDIT THE DATABASE
Don’t just open the original database file from your local installation and edit it. DB ata stored serialized will break if edited directly in a text editor. You are better off with a serialize-aware tool like Search-Replace-DB (thanks, Andrey Savchenko!). Replace the old, local URL for the website with the new, remote URL.
So for example, if your local URL is http://localhost/example
, you would change it tohttp://example.com
.
Using the “replace” command will speed this up — there could be thousands of instances. Save your new database.
5. DROP THE EXISTING REMOTE DATABASE
Note: This step only applies if you’ve used a script such as Softaculous or Fantastico to install WordPress, as they automatically create a new database. If you’ve installed WordPress manually, you can ignore this bit.
In phpMyAdmin, drop (delete) the database that was installed in the remote website when you installed WordPress:
- Select the database you’re working with.
- Click on the “Structure” tab.
- Below the list of tables, click “Check All.”
- In the drop-down menu which says “With selected,” select “Drop”:
Larger version. - You will see a warning message checking that you want to drop all tables. Click “Yes.”
- Finally you will see a message telling you that your query has been implemented:
Larger version.
6. UPLOAD THE NEW DATABASE
While you are still in phpMyAdmin, upload the database you’ve edited:
- Click the “Import” tab.
- Click the “Choose file” button.
- Select the database you saved in step 4 and click “Choose” or “OK.”
- Click the “Go” button.
- After a while (depending on the size of your database), you will see a message telling you the upload has successfully finished:
7. CLEAR YOUR BROWSER’S CACHE
This avoids any problems you may have if the browser has cached content from the old version of the remote database.
8. LOG INTO THE WORDPRESS ADMIN FOR THE REMOTE WEBSITE AND UPDATE PERMALINKS
Your log-in details will be the same as for your local website. If you specified different log-in details when installing remotely, these will have been overridden by the imported database.
Visit the “Permalinks” screen and turn pretty permalinks back on.
You’re done!
Moving A WordPress Website Between Hosts
This process is almost exactly the same as that for uploading a website from a local installation. The only difference is that you need to download the files and database from the existing website.
Follow the above process, with changes to step 2:
2. DOWNLOAD AND BACKUP THE OLD DATABASE AND FILES
In phpMyAdmin for the old website, select the correct database and click on the “Export” tab. Download the database by clicking the “Go” button. The database will download to your machine.
Move the database out of your downloads folder to somewhere useful and make a copy of it. You’ll be working with this database in Step 4.
Using FTP or SFTP, download the contents of wp-content
from your old website. You will upload this to the new website in step 3.
Now return to the original process.