Move WordPress from Subdomain to Root

Installing WordPress in a subdomain is a great way to create a staging environment for development. The subdomain (for example http://dev.askwpgirl.com) is a self-contained space to do development without interfering with the live site. When the development phase is complete, the question becomes “How do you move WordPress from the subdomain to the root?”

Note: If you installed WordPress in a subdirectory (e.g. http://mysite.com/subdirectory) and not in a subdomain (http://subdomain.mysite.com), then please see How to move WordPress from a subdirectory to the root.

You can “move” WordPress from the subdomain to the root domain using one of the following approaches:

  • Back the site up using a backup or migration plugin (such as BackupBuddy, Duplicator, or All-in-One WP Migration). While leaving the subdomain of the site intact, you can restore the backup of the subdomain to the root directory. This is a nice option as it allows you to keep the WordPress install in the subdomain as a perpetual staging environment for testing WordPress updates or trying out new plugins or code.
  • If you do not want to maintain two WordPress installs on your hosting account (which is twice the work as maintaining one site and necessary to prevent hacking), you can do one of the following:
    • move the WordPress install to the root directory
    • keep the WordPress install in the subdomain folder, but rewrite the URLs to display them from the root
    • use one of the plugins mentioned above to “migrate” the dev site to the root directory then delete the subdomain.

Below are instructions for how to move or show the site from the root directory without using a migration plugin.

Before moving WordPress from the subdomain to the public_html (aka www or “root”) folder

Note: When I say “root” I mean the domain root NOT the hosting root folder. The domain root folder is typically called html, www, or public_html on most web hosts. Some WordPress installs are pretty gnarly with folders inside of folders inside of folders, and finding the folder that the host considers to be the primary domain root folder can take some digging.

1 – Be sure you have access to your web hosting control panel and File Manager within the control panel as well as access to phpMyAdmin should you need to revert the changes you make to the WordPress General Settings below.

2 – Make a back up of your database using UpdraftPlus or BackWPUp plugin. Download this file and keep it safe.

3 – Remove any old site files from the public_html directory — perhaps copy them to a folder called _backup – this includes an index.html file which will totally make this process not work. You MUST remove all those old site files and folders or move them into another directory, so they don’t interfere with WordPress. Having an index.html and index.php in the same folder causes confusion, and likely, the index.html will be used instead of WordPress’ index.php file. Do not move server related folders in the public_html directory such as cgi-bin. It’s okay for those to stay in place.

4 – Make sure you don’t have any other folders in the root directory that have the same name as any pages on your WordPress site, for example “blog” unless of course this is the name of your subdirectory install of WordPress in which case you cannot have a page of the same name because the browser will get confused and look for that page in that folder, then things are really confused.

5 – If you are using a caching plugin, delete all cached pages and de-activate caching.

Option 1: Move WordPress from subdomain folder to public_html directory

This is the most straight forward process to get WordPress out of the subdomain and into the root directory.

1 – Go to Settings > General and change the URL for both the WordPress Address and Site Address to use the main domain name. Be sure to remove the trailing / . Click Save Changes.

general-settings

2 – Using FTP or the web host’s File Manager, you will need to MOVE all of the WordPress files from the subdomain’s folder up one level to the public_html aka domain root folder.

To do this with FTP, in the remote server area of the FTP application window, toggle open the subdirectory containing the WordPress installation you wish to move. Select all the files in this directory and drag them out of this directory and into the public_html folder or whatever directory this directory is within.

If you are using the File Manager on the web host’s control panel:

  • Double click the subdirectory containing the WordPress files to expand it open.
  • Click Select All to select all the files and folders.
  • Click the Move File icon.
  • In the Move dialog box, remove the subdirectory from the path field, so the path you are moving to is /public_html
  • Click Move Files.

(Note: Some hosts might have a different name for this folder or you may have installed WordPress in a subdirectory inside another directory. Just remove the current subdirectory from the path along with the forward slash /, but don’t remove anything more than that.)

The files should now be moved to the public_html.

file-manager

3 – Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.

4 – Go to Settings > Permalinks and click Save Changes. This will rewrite the .htaccess file that controls the  “pretty” URLs on the site. This likely isn’t going to be an issue when you are using a subdomain install, as the .htaccess contents should be correct.

5 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, type the subdomain website address in the Old URL field and the main website address in the New URL field.

Be sure to not end the URLs with a forward slash /. If you do end it with a forward slash, end it with a forward slash for both URLs not just one. Consistency is important here.

Be sure to NOT not update all GUIDs. This will result in many theme settings to reset and posts to republish to the RSS feed.

6 – Click the Update URLs button. This should catch most of the URLs on the site. However, if it seems to miss several, you can try repeating this process without the http:// part of the URL, and see if it catches more.

Moving WordPress Subdomain to Root using Velvet Blues Update URLs plugin

7 – Check for other URLs not caught with the Velvet Blues plugin including:

  • Appearance > Menus — check for any custom URLs to the old site URL in any custom menu items, such as the home page link.
  • Appearance > Theme Options or your theme’s Theme Options page — check the URLs for any uploaded files such as the logo or favicon and remove the subdirectory from the URLs as needed.
  • Sliders — If you use Revolution Slider or other slider plugin may not update the URLs to the slider images with the Velvet Blues plugin. Edit the slider and remove the subdirectory from any image URLs.
  • Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the subdirectory which you may need to manually change. If you can find a pattern to these, you can try to run the Velvet Blues plugin again using the URL pattern you find.

8 – Test the site and be sure everything is appearing as expected. If anything is amiss, be sure to clear your browser cache completely or test in a browser you don’t usually use.

9 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed.

Please comment below if you have any issues, as I can write more instructions for troubleshooting as needed. The main issue with this technique is that it’s possible for people to move the WordPress files BEFORE making the URL edits in the General Settings, and that will make the site inaccessible. However, this is quickly remedied by going into phpMyAdmin and accessing the wp_options table and changing the site and home URL as needed.

Option 2: Keep WordPress in the subdomain’s folder but show the URLs from the root

This option is slightly less intimidating because it doesn’t involve moving all the WordPress files. You only need to copy one file and move that to the public_html directory. This process will not allow you to access the WordPress installation via the subdomain any longer. It simply allows you to keep WordPress in the subdirectory (aka subfolder) on the hosting account created for the subdomain but essentially makes the subdomain not usable unless you recreate the subdomain and have it point to a different folder.

The only issue with the process below is if you created a not-so-user-friendly subfolder name for the installation, such as “dev” or “test” or “staging.” This would not be a professional folder name to use on a live site. Even though this process will allow you to show the URLs from the root of the domain, your uploaded images, PDFs, and other media files will reference the subdirectory (subfolder) name.

Changing the WordPress Subdomain/Subfolder Name

If you want to throw complete caution to the wind, you could go ahead and rename the subfolder, and I will tell you below EXACTLY at which point in the process to do so, so you don’t lock yourself out of the site. But, have no fear! If you do mess up the folder name or the URLs, you can always fix this in the database using phpMyAdmin. In fact, trying this process on non-critical websites can build confidence in future migrations. Breaking things is always a great way to learn! Just maybe not on a client’s site.

Keeping WordPress in the subdomain folder but showing URLs from the root

1 – In your web hosting control panel File Manager or FTP application, please take note of the folder name of the subdomain installation. This is typically the same name as the subdomain, e.g. dev, staging, blog, test, etc., but sometimes it is different, so make sure you know what it is before proceeding.

2 – Go to Settings > General. What you will see is something like this:

subdomain-general-settings

You need to change the URLs to this where the WordPress Address is the main domain URL with a forward slash followed by the folder name you made note of in step 1 above, and the Site Address is the main domain URL.

subdomain-folder-name

Now is the opportunity to CHANGE the folder name but don’t do it in the File Manager or FTP yet. If you want to use a different folder name, enter that in the WordPress Address field, e.g. http://mydomain.com/newfoldername, then we will rename the actual folder in step 4 below.

3 – Click Save Changes. You will be immediately kicked out of the site.

4 – If you changed the folder name in the WordPress Address field, go ahead now and change the folder name in your control panel’s File Manager or FTP application.

5 – While you are in the File Manager of FTP application, download the index.php file in the subdomain’s folder.

6 – In a text or HTML editor, open the index.php file that you just downloaded and change the location of the wp-blog-header.php to tell WordPress where it can find the WordPress application files in the subdirectory:

Example: if your WordPress installation folder is ‘subdomain’, you would change:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to

require( dirname( __FILE__ ) . '/subdomain/wp-blog-header.php' );

Important: Be sure you type this correctly! A missing / or too many slashes or missing period or apostrophe can make this not work. Believe me, I’ve seen people be totally freaked out things didn’t work and it was because they typed this line wrong.

Do NOT edit this file in Word or any text editor that uses Rich Text as it will turn the straight quotes curly and will break your site. If you don’t have a code editor application, then upload the file to your hosting account (see Step 7 below) and then edit it using the Editor feature in the File Manager instead.

7 – Upload this edited index.php file to the public_html folder on the hosting account. The file structure will look something like this:

cpanel-file-manager

8 – Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.

9 – Go to Settings > Permalinks and click Save Changes. This will rewrite the .htaccess file that controls the  “pretty” URLs on the site. This likely isn’t going to be an issue when you are using a subdomain install, as the .htaccess contents should be correct.

10 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, update your URLs as follows:

velvet-blues-change-subdomain-subdirectory

In the New Site Address field enter the URL to the correct folder name for the WordPress install that is in your Settings > General for the WordPress URL.

Be sure to not end the URLs with a forward slash /. If you do end it with a forward slash, end it with a forward slash for both URLs not just one. Consistency is important here.

Be sure to NOT not update all GUIDs. This will result in many theme settings to reset and posts to republish to the RSS feed.

11 – Click the Update URLs button. This should catch most of the URLs on the site. However, if it seems to miss several, you can try repeating this process without the http:// part of the URL, and see if it catches more.

12 – Check for other URLs not caught with the Velvet Blues plugin including:

  • Appearance > Menus — check for any custom URLs to the old site URL in any custom menu items, such as the home page link.
  • Appearance > Theme Options or your theme’s Theme Options page — check the URLs for any uploaded files such as the logo or favicon.
  • Sliders — If you use Revolution Slider or other slider plugin may not update the URLs to the slider images with the Velvet Blues plugin.
  • Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the subdirectory which you may need to manually change. If you can find a pattern to these, you can try to run the Velvet Blues plugin again using the URL pattern you find.
  • Any manual links to internal pages will need to be edited to point to the domain without the subfolder in the URL.

13 – Test the site and be sure everything is appearing as expected. If anything is amiss, be sure to clear your browser cache completely or test in a browser you don’t usually use.

14 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed.

This process is obviously more steps, and you need to be careful with each step to make sure you type the correct URL and folder names. Otherwise, it’s actually pretty simple. I think the most difficult part here is that you essentially going from a subdomain install to a subdirectory install then taking it one step further to show the URLs from the root domain and in this whole process you may have gone wild and decided to change the folder name while you were at it!

Fixing WordPress URLs in phpMyAdmin

For both of these processes, the main mistake that might be made is to the URL fields. A simple typo can really cause problems. To fix this, log in to your web hosting control panel and go to phpMyAdmin. If you are prompted for a username or password for the database, you can find both of these in the wp-config.php file in your WordPress install. (Tip: In the File Manager, you can view the wp-config.php file and copy the username and password to a text file on your computer for easy reference.)

1 – Once in phpMyAdmin, click on the wp_options table.

2 – Click the Browse tab at the top of the phpMyAdmin to see the contents of the wp_options table.

3 – Look for the two options names: siteurl and home.

phpmyadmin-wordpress-wp-options-siteurl

4 – Check to make sure these are correct. If you did the process outlined in Option 1 above, both of these should be simply the website URL (e.g. http://mysite.com). If you did the process outlined in Option 2 above, the siteurl should contain the subfolder name. Check the File Manager or FTP application to make sure you have it correctly entered. The home URL should be the main URL for the site.

5 – If you need to edit these, click the pencil icon, make the changes, then click the Go button to save the changes.

Let me know if you get stuck! Write in the comments or contact me directly. I can often provide quick advice. If things are not easy to address via email, I am available for hire. It typically takes me 5-15 minutes to login and figure things out.

I would love if you could Tweet about this if it helped you!

Angela Bowman

Front-end WordPress developer since 2007 building highly custom websites for nonprofits and small businesses. Experienced in nonprofit administration, grant writing, and technical writing. Love high altitude hiking and backyard chickens.

18 comments on “Move WordPress from Subdomain to Root

  1. I attempting option 1 right now and i moved my folder to the public_html and now when i access wp_admin all information from temp site is lost and its like a blank new site. Is there any way to recover this ?

    • Hi John,

      Your site is not lost, and none of your data has been lost. So don’t panic. This results from a typo or not moving your files correctly or the domain not being pointed correctly.

      When I go to your website URL, it looks like your domain is not pointing to a web hosting account. Let me know what domain name you are trying to move. If it’s the johnmalecki.com domain, then you need to point that domain to the host where you have your WordPress files you are working with. It looks like the domain is pointed to Blue Host. There is also no www record set up for your site on your DNS record, and it has recursive queries on the DNS record.

      So, check your domain set up and which host you are actually using for your domain and make sure you have the domain correctly added to and pointed to your hosting account.

      Angela

  2. Hi, Angela! Tremendous resource here! I’m in the process of manually moving a WP site from a subdomain to a root domain for the first time.

    So, quick question (showing my ignorance here): Do I need to install WP on the primary domain before moving the subdomain files, or does moving the file essentially ‘install’ WP on the root?

    Thanks in advance!

    • Very good question, Tony. No, you do not need to install WordPress in the primary domain. Moving the files does essentially “install” WP in the primary domain. The issues that can arise are related to the web host and how they perceive this install. Sometimes the host is trying to micromanage the installation, such as on GoDaddy and Network Solutions. Let me know how the process goes for you.

  3. Angela: thanks so much for taking the time to write such excellent instructions! I used them to help me manually move my school’s site from a subdomain to the root, and everything worked!

  4. If there are other subdomains on the main (I had just used a subdomain to set up my new wordpress site to get rid of the old joomla site on the main) will that affect anything if I try option 2?

    Also, as a temporary fix, I had redirected the domains to my wordpress subdomain. Will I need to remove those first?

    Thanks!

    • Good questions!

      As long as the primary domain points to the public_html (aka root directory), then you could use option 2.

      The other subdomains will continue to function in their respective directories.

      You will need to remove the redirects to the subdomain as the redirects result in the domain pointing to the directory containing the subdomain instead of to the public_html folder.

      Let me know how it goes!

  5. Thank you! I just followed your instructions for a small website and it worked perfectly. My only issue was to do with Wordfence. I had moved the file with the main domain wordpress files, but also had it installed for the subdomain, so I received a 500 server error. I tracked it down through the log files on my host and copied the missing wordfence file back, and everything was fine. The whole process of moving did not take long, but the backup process, including installing the plugins for both sites, took a bit. Gotta have those backups!

    • Hi Jennifer, yes, having backups is a good idea. Wordfence is a bit of a bear. I’ve gotten a bit frustrated with it over the years and started using this plugin instead: https://wordpress.org/plugins/wp-simple-firewall/

      Security and caching plugins can definitely muck up this process a bit, so I do recommend clearing the cache and de-activating. Wordfence is quite invasive and thus creates more site migration challenges. If people do want to migrate a site with an existing Wordfence install, I recommend going to the Wordfence options and checking the checkbox option to delete all Wordfence tables and data on de-activation. This will completely uninstall Wordfence when you de-activate it. Then, you can migrate the site, re-activate Wordfence and reset the settings. This would avoid the issues you had an ensure that it will work properly under the new URLs.

  6. I tried option 2 but got an error and had to switch everything back in wp-options. It almost looks like you have combined the instructions for subdirectories with subdomains?
    I built a fresh site in a subdomain and wanted to just redirect the main domain to it – like you can with .htaccess rewrite rules for subdirectories but that didn’t seem like it would work.
    After debating far too long over the best approach I discovered a brilliant option I hadn’t even thought of before – I posted a support ticket to my host server and they just migrated the whole thing in minutes! I had no idea – duh. So this might be a suggestion for others. I’m at ICDSoft and they use cpanel – likely plenty of other hosts will provide this service too (it’s free)

    • Hi Eveline,

      The instructions on this post are specifically for moving a SUBDOMAIN to the ROOT domain. And subdomains are typically installed in a subdirectory in the public_html folder. Hence why I mentioned subdirectory in this post.

      You cannot redirect your main domain to your subdomain. Most hosts will not allow that.

      So, yes, asking your host, if they are a good host, to migrate it for you is a great idea! Glad they were willing to do that. Sometimes they can redirect the primary domain to another folder on the site then rewrite the URLs on that install, and it works great!

  7. Hey Angela,

    A big thanks for pulling this together and keeping it simple.

    I’ve been building an e-commerce site using the WooCommerce Storefront theme plus several WooCommerce extensions.

    I used option 1 to move the new site to production and it worked exactly as you have it laid out above.

    The only item that didn’t change the URL was a gallery plug-in which I had to manually update. Apart from that, it was easier than I expected.

    Thanks again,
    Dave

    • Hi Dave,

      I’m so glad that worked out for you! Yes, sometimes plugins and themes will store absolute instead of relative URLs, and you have to manually edit them.

      Be sure to check your logo and any other assets that might be in theme options or other settings, too!

      Angela

  8. Thanx for this comprehensive but still good-to-follow steps! Just migrated my new site from dev.url to url without a hassle in 30 minutes. Only thing is, I can;t get my contactform working. Any experience with this before?

    • Hi Matthijs,

      Did you get your contact form working? I recommend Formidable Forms for free contact forms. https://wordpress.org/plugins/formidable/ It’s very reliable. I wonder if maybe your captcha was set up for the old site and needs to be updated to work with the new site?

      Let me know how things are going.

      Angela

  9. Angela Bowman

    Thanks for writing such clear instructions. I used your manual instructions rather than using Duplicator to move from my subdomain to the root directory. Your instructions were easy to follow and I had no problems.

    • I am glad the manual instructions worked. I usually do it manually. You should check your theme options to be sure your logo or any other background images set with the theme are using the correct URL. The Velvet Blue Update URLs plugin works pretty well, but it does miss some things in premium theme options and links in page layout builders. There are other plugins that are more effective at getting everything, but they can also mess things up.

Leave a Reply

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