How to Move WordPress from a Subdirectory to the Root Directory

Updated on Dec 7, 2022

A subdomain is an extension of your root domain name. For example, https://yourwebsite.example.com is a subdomain of example.com. In this case, example.com is the root domain.

Subdomains are treated as separate websites by search engines. This is why you must ensure that search engines are properly redirected to the root domain following the transfer. This will assist you in retaining search rankings after moving your website.

Moving a WordPress site to the root domain is simpler than moving it to a new host or domain name.

Because both are typically hosted by the same web hosting company, you can skip a few steps.

This post includes:

Why Install WordPress in a Subdirectory?

Installing WordPress in a subdirectory can be a good idea because:

  • It keeps your root directory tidy and clean (in case you need to add any other PHP applications to your site).
  • It adds a layer of security by hiding the location of your WordPress application files. Ideally, you should name the subdirectory something that isn't too obvious (for example, don't call it wp or WordPress). I'm not sure how obscure this makes WordPress, because you can obviously get the subdirectory name from any images uploaded to the site because they will still read as sitename.com/subdirectory/wp-content/uploads/image.jpg, so I usually install WP in a subdirectory for development purposes or simply to keep the root directory clean in case I install any subdomains or other applications.
  • It enables you to create a new WordPress site while keeping your existing site in the root directory. When you're finished with your WordPress development, you can back up and then delete your current site's files, and then use the instructions below to display WordPress from the site's root directory.

Note

If this is an older site, you'll need to set up 301 redirects to point your old page/post URLs to the new page/post URLs. You will also need to manually update any internal hyperlinks if you have a large number of them.

Before the Move

Here’s what you should do before attempting to move your WordPress site:

  • Clear the cache of ALL pages cached by your caching plugin, and then deactivate the caching plugin. Deactivate Broken Link Checker and any Redirection plugins as well.
  • Remove any old site files from the root directory, perhaps by copying them to a folder called _backup - this includes an index.html file, which will completely break this process. All old site files and folders must be removed or moved to another directory, so they do not interfere with WordPress. Having index.html and index.php files in the same folder causes confusion, and the index.html will most likely be used instead of WordPress' index.php file.
  • Make sure you don't have any other folders in the root directory with 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 can't have a page of the same name because the browser will get confused and look for that page in that folder, which is when things get really confusing;
  • Use wp-db-backup to make a backup of your database;
  • In case you type the URLs incorrectly in the next step, make sure you have access to your database via phpMyAdmin in your web host's control panel. The wp-config.php file contains your database username and password.

How to Move WordPress Installation from Subdirectory to public_html Directory

  • Remove the subdirectory from the URL for both the WordPress Address and the Site Address by going to Settings → General. Please remove the trailing /. Both addresses should simply end in.com,.org, or whatever domain type is used. Click the Save Changes button.
  • You must use FTP or the cPanel File Manager to move all of the WordPress files from the subdirectory to the root.
  • To do this via FTP, open the remote server area and navigate to the subdirectory containing the WordPress installation you want to relocate. Drag all of the files in this directory out of here and into the public HTML folder or whatever directory this directory is in.
  • If you are using the File Manager:
    • Double-click the subdirectory containing the WordPress files.
    • Click Select All to select all the files.
    • Click Move File.

In the Move dialog box, remove the subdirectory from the path field, so the path you are moving to is /public_html

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.

  • Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. https://mywebsite.com/wp-admin.
  • Go to Settings → Permalinks and click Save Changes. This will rewrite your .htaccess file to remove the subdirectory from the page URLs.
  • Install and use an URL update plugin like Go Live Update Urls.

in the Old URL field and the website without the subdirectory in the New URL field.

Make sure the URLs do not end in a forward slash /. If you must use a forward slash, use one for both URLs, not just one. Here, consistency is essential.

Make sure not to update all GUIDs. This will result in many theme settings being reset and posts being republished to the RSS feed.

  • 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 https:// part of the URL and see if it catches more.
  • Check for other URLs not caught by the 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, that may prvent the update of the URLs of the slider images. 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 URL update plugin again using the URL pattern you find.
  • Check the site to ensure that everything is as it should be.
  • Reset the caching and update the.htaccess file as directed by the caching plugin. Test the site again in a different browser to ensure that the pages are correctly caching.
  • Finally, to avoid losing all SEO credit for the old site, implement a wild card redirect from the old URL to the new one. To accomplish this, use the File Manager or FTP application to add the following code to the top of your .htaccess file, substituting YOUR domain name and subdirectory name. (Please keep in mind that .htaccess is an invisible file.) To see this file, you must select Show Invisibles in the File Manager or FTP client.)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com/subdirectory$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com/subdirectory$
RewriteRule (.*)$ http://www.mydomain.com/$1 [R=301,L]

On the RewriteRule line, use www or don’t use www according to what you have in your Settings → General. For example, if you don’t have www in your URL in the General Settings, do not include the www in the RewriteRule line.

Note

To begin, change this rule to 302 instead of 301 and test it by entering one of your URLs with the subdirectory in it and ensuring that it rewrites to the same URL without the subdirectory. Change the 302 to 301 once you're sure it's working. 302 is considered temporary, is not used for SEO, and browsers do not cache it. Google considers 301 to be a permanent change that transfers the SEO credit of a page from one URL to another and is cached by browsers.

Conclusion

That's it; you've successfully transitioned your site from a subdomain to a root domain. You can now see it in action by visiting your website. Check your website to ensure that everything is in working order.

We hope this article was useful in transitioning your site from a subdomain to a root domain.

We hope you find this article useful. Discover more about FastCloud - the top-rated Hosting Solutions for personal and small business websites in four consecutive years by the HostAdvice Community!

WordPress Hosting

  • Free WordPress Installation
  • 24/7 WordPress Support
  • Free Domain Transfer
  • Hack-free Protection
  • Fast SSD Storage
  • Free WordPress Transfer
  • Free CloudFlare CDN
  • Immediate Activation
View More