
Migrating wordpress website from subdirectory to root directory
Description :
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.
Note : This method will not work for multisite installations, only for standard single-site installations.
—-
Step 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-.
Note : Don’t remove the existing site until you have made a backup.
Step 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.”
Step 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.
Step 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 site 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:
require ('./wp-blog-header.php)
to
require ('./subdirectoryname/wp-blog-header.php)
So if you’ve been developing in example.com/development, just change the line to:
require ('./development/wp-blog-header.php)
Save the new index.php file.
Step 5 : Turn Permalinks back on
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