Skip to main content
 How to painlessly move WordPress from a  Subfolder to Root Folder or From One URL to Another

WordPress is probably, hands-down, the easiest Content Management System available today for building your website.  However, one of the trickier aspects of managing a WordPress website comes to light, should you ever need to move it from one folder to another or from a subfolder on your web hosting server to the main root folder.

One common scenario where this might come up would be if you wanted to build your new WordPress website in a subfolder while keeping your current website live in the main root public/html folder.

Example 1:  www.yourdomain.com/wordpress/ to www.yourdomain.com

Another scenario would be if you’re changing your website domain URL entirely from one domain to another.  Whereas, we demo many of websites on our dedicated development server.   However, when we need to move the site to go live, the domain will need to be that of the new website.

Example 2:   http://90ddev.com/name_of_website to  http://name_of_website.com.

Before I start giving you the blow-by-blow process, the absolute fastest, easiest and hands-down, BEST way to move your website website is to use BackUp Buddy.  However, this is a paid plugin, albeit very much worth the money!

With other website building environments, it’s an entirely acceptable – and relatively easy – solution to use your .htaccess file to simply redirect your website’s domain to the subfolder and hide the subfolder in the URL path. Due to the way it generates it’s URL structures, WordPress does not like redirects.  So save yourself the grief and do not attempt this with a WordPress website.

It’s easy and logical enough to assume, if you’re a WordPress newbie, that it will work just fine to move the site files from the subfolder right into public_html folder and things will work just fine.  If you’ve already tried this, you probably found your website broken and were unable to access the WordPress admin.  This is because you have not changed the “Site” and “Home” URL’s.  This can be done in the WordPress admin just BEFORE you make the move – and I say just before because it will break your site until you move it to the main folder.  However, I save this for a later step in the process because I know I’m going to be searching and replacing all my URL paths anyway, so these will get changed in the process.

This relatively fool-proof, step-by-step process works well for both scenarios with minimal headaches and no additional plugins needed.

IMPORTANT:  If you’re not moving the site from one host or server to another, and simply need to move the files from one folder to the main root folder, please see skip to step 2.a.

Step 1:  Archive Your Website Files

The best way to do this is via cPanel or whatever website hosting panel your web host offers (they all have some sort of management portal).  Once logged in the your hosting panel, locate the File Manager, which will open a window from which you can browse to find the directory in which the site files you will be moving currently resides.  Click on the folder and look for a link (usually located around to the top of the window) that says something like, “Compress” or “Archive.”  Name your archive something like your_site.zip.  This will package and compress all the files so they’re easier and faster to download.

Step 2:  Download Your Website Files & Upload them to the New Location

Once you have a .zip archive of your site files, you’ll need to download the zip file to your computer and keep it in safe place for a backup.  Then you’ll want to head over to the new server location and upload the zip archive of your site files into the public_html directory.

Step 2.a – If you are simply moving the site from one directory to another on the same server, then you only need to select all the site files and move them to the public_html or root folder.  You can do this in the file browser of your hosting cPanel or via FTP.  Most FTP clients have some sort of “MOVE” or “MOVE TO PARENT DIRECTORY” option that will make this very easy.

Step 3 – Download a copy of your mySQL database

The second component other than the site files that you need to move is the website database. Once again, you should only need to do this step if you are moving the site from one server to another. To grab a copy of your database, once again start from the cPanel dashboard of your website host.  Look for a link or icon that says, “PhpMyAdmin.”  Click that link to open PhpMyAdmin.  PhpMyAdmin is a handy WYSIWYG tool for administering your MySQL database.  It only looks intimidating.  Don’t worry; you’re just going to do about three clicks here and then get out.  First, turn your eye to the left hand side of the window just under the PhpMyAdmin logo.  Click on the title of your database.  You may to expand the plus signs if you have multiple databases in your hosting account.  You’ll need to make sure you’re clicking on the correct database (Totally ignore the links that say “Information Schema” – those are immaterial to your mission).   Once you’ve clicked on your WordPress website’s database, turn your to the right of the page and look for a tab entitled, “EXPORT” and click it.  This will open the Export window.  Depending on what version of PhpMyAdmin your host is using, you may be given the option to check a box that says “Save as file.”  If you see this, check it.  If not, simply click “GO.”  This will start a download of the .sql file.  Make note of where that file went when it downloaded, because you’ll need it in just a few minutes. Store a copy of this file somewhere safe for backup purposes.

Step 4 – Download a copy of Search and Replace Database

One the handiest tools out there, this simple, free script has made my life so much easier, and God bless the person who wrote it, it’s FREE.  So you’re just going to download this, unzip it and copy it over to the folder in which your current WordPress website resides.  Because WordPress makes gratuitous use of absolute URL paths, you are going to need to search ALL the old URLs and replace them with new paths.  Otherwise, you’re going to have a whole lot of broken links and image paths once you’ve moved your website files.  When the Search and Replace Database folder has finished uploading, navigate to that folder in your browser window:

Example:  www.yourmainsite.com/wordpress/Search-Replace-DB-master

If you’ve uploaded the folder and entered in the URL correctly you will see a red and white interface that has two fields at the very top of the page for searching for one string (or URL in this case) and replacing it with another.  You will want to be very accurate with what you type in here. Your inputs here will look something like this:

Search for:  http://www.yourwebsite.com/wordpress/   Replace With:  http://www.yourwebsite.com/

Now repeat this step but leave out the trailing “/”:

Search for:  http://www.yourwebsite.com/wordpress   Replace With:  http://www.yourwebsite.com

Step 5 – Repeat Step 3 – Download a copy of your mySQL database

Just repeat step 3 again to download the new copy of your database.

If you’re simply moving your site from a subdirectory, you’re almost done!  You should be able to access your new site admin at the new URL:  http://www.yourwebsite.com/wp-admin

Login to the admin and go to Settings>Permalinks and just re-save your permalinks.  This will initiate WordPress to rewrite all the permalinks with the new information.  If you’re moving from one server to another proceed on to step 6.

Step 6 – Repeat Step 3 – Download a copy of your mySQL database

Just repeat step 3 again to download the new copy of your database.

Step 7 – Create a new database on new server*

From the hosting panel or cPanel, login and navigate to a link which is called something like mySQL databases.  Click it and then click “Create a New Database.”  Choose a name for the database.  You’ll then need to create a user and password for the new database, so go back and click, “Create new user”.  Choose a user name and password.  IMPORTANT STEP – You’ll then need to ADD that user you just created to the database.  You’ll see a couple of drop-down menus in the database admin page which allows you to choose a database (your new one) and then choose a user to assign to that database.  Choose the user you just created and click “ADD.”  The next screen will give you a page with lots of checkboxes for assigning privileges to the new user.  Make sure you click “All Privileges”.

*Your process for doing this may vary slightly depending on what hosting panel you are using.  These instructions were written based on cPanel.

Step 8 – Import your database

Once again, go back to the cPanel and launch phpMyadmin for your newly created and currently empty database.  Click on that empty database on the left and then click “Import” tab over to the right.  Use the “browse” button to browse your computer to locate the most recent .sql file you downloaded (the one you downloaded after you made the find and replace changes).  Import that file.  When it finishes, you should be done with phpMyadmin.

Step 9 – Update your wp-config.php file

Either via the File Manager browser or via FTP locate and open the wp-config.php file in the root of your WordPress site.  Update that file with your new database information, making sure to use the correct database, username and password as well as the correct hosting server path (usually localhost).

Step 10 – Re-save your permalinks

Just as described in step 5, you should now login to the WordPress admin and go to Settings>Permalinks and just re-save your permalinks.

Step 11 – Delete the Search and Replace Folder

Be sure to delete that Search and Replace Database folder from your site files.  You don’t want to leave that out on the interweb for anyone to access your database!

That’s it!  You’re done.

Leave a Reply