Moving WordPress from Sub-Directory to Root Directory

In my blog post How do I move WordPress from a subdirectory to root directory, I describe a process in which you don’t have to physically move the WordPress installation but can make a few settings changes in order to have the URLs for posts and pages display from the root while leaving the WordPress application and uploaded files in the subdirectory. This is a great strategy if you want to keep your directory structure clean, avoid having to rewrite a lot of URLs, and don’t want to deal with moving a bunch of files around on the server.

However, you may not want to use the subdirectory any longer and instead really do want to migrate WordPress from the subdirectory to the root directory. Below are steps to accomplish this.

(Tip: Instead of the process below, you can use the Duplicator plugin to create an archive zip of the entire site and restore the archive in the root directory. The benefit of using the Duplicator plugin is that the restore script will automatically rewrite all the URLs for you. However, duplicating a very large site might be a bit onerous and the archive process might not work well on some web hosts that have potential to time out when creating large archives.)

Before migrating WordPress from subdirectory to root directory

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 root 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;

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.

Moving WordPress installation from subdirectory to public_html directory

1 – Go to Settings > General and remove the subdirectory from the URL for both the WordPress Address and Site Address. Be sure to remove the trailing / . Both addresses should simply end with .com or .org or whatever the domain type is. 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 subdirectory up one level to the root.

To do this with FTP, in the remote server area, 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.

– 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.)

– Click Move Files.

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 your .htaccess file to remove the subdirectory from the page URLs.

5 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, type the website address containing the subdirectory in the Old URL field and the website without the subdirectory 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.

Update urls

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.

9 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed. Test the site again in a different browser to be sure the pages are caching correctly.

10 – Finally, to keep from losing all your SEO credit on the old site, you will want to implement a wild card redirect from the old URL to the new one. To do this, add the following bit of code to the top of your .htaccess file using the File Manager or FTP application substituting YOUR domain name and subdirectory name. (Note: .htaccess is an invisible file. You must select in the File Manager or FTP client to show invisibles in order to see this file.)

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.

Pro tip: To start, set this rule to 302 instead of 301 and test it to make sure it is working by entering one of your URLs with the subdirectory in it and make sure it rewrites to the same URL without the subdirectory. When you are sure it is working, change the 302 to 301. 302 is considered temporary and is not used for SEO and is not cached by browsers. 301 is considered a permanent change and is considered by Google to transfer the SEO credit of a page from one URL to another and is cached by browsers.

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.

View all posts by Angela Bowman

67 comments on “Moving WordPress from Sub-Directory to Root Directory

  1. [* Shield plugin marked this comment as “0”. Reason: Human SPAM filter found “my website” in “comment_content” *]
    Hi Angela, congratulations for your clear guide. Unfortunately I discovered it too late. I had already tried to move my website from directory too root. Now I think I did everything but maybe not in the right order. Typing http://www.mysite.com I still see the old homepage (just a draft I had made with an option cpanel allows). I moved to another folder the files index.html and other ones I think they referred to that old page. The old URL mysite.com/blog doesn’t work. But new articles show up. Only the homepage is missing. What can I do? 🙁 thanks!

  2. I’ve tried all these and yet can’t seem to get it done. I get a database connection error. I resorted to redirecting the root to the subdirectory.

    Is there a simpler way please?

    Thanks

  3. Hi . This was quite useful when I moved my website from a subdirectory to root. I can say it is working well except for one thing.
    I will try to explain my problem using URLs
    I had moved from http://www.xyz.com/Travel/ to http://www.xyz.com/ where Travel is the subdirectory
    All accesses to http://www.xyz.com/Travel/* gets converted to http://www.xyz.com/* e.g. http://www.xyz.com/Travel/places gets converted to http://www.xyz.com/places which is correct. However http://www.xyz.com/Travel does not get converted to http://www.xyz.com and so gives page not found error.
    The htaccess I am using is as follows. Can you help me find the error? I am not good at htaccess coding.

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

    • Hi Vasu,

      You should not and do not need to use the Rewrite code you have. I would remove that and then go to Settings > Permalinks and save your permalinks to make sure the .htaccess file is written correctly.

      Many themes or the custom menu have the OLD home page URL hardcoded. So you want to be sure that the URL for the home page is correct in your menu.

      A

      • Thanks Angela,

        I just wanted to ensure that apache will correctly resolve all my old web links that are floating around over the last several years.

        I will do what you suggest and check

        Cheers!
        Vasu

        • Usually Apache will not resolve the web links. In this case, if you are moving the installation (WordPress files, etc.) into the public_html directory, you can use the htaccess redirect in step 10 to resolve these links automatically.

          After making the move, use that htaccess redirect snippet (substituting your domain name for the mydomain.com name). Set the redirect to 302 instead of 301 and then test a few of your old links and make sure they are redirecting correctly. After you have confirmed it is working, change the 302 to 301 (permanent), which will retain the page rank/seo value of those older URLs and transfer that value to the new URLs.

  4. Thanks for this very informative post WP Girl. Migrating WP is always a headache but it went pretty smoothly this time thanx to you. Just a note for your other readers who may happen to be using Godaddy… the .htaccess file is not copied when you use the cPanel’s file manager to move the files. You wont even see the .htaccess file. I had to use a program called windows grep to do a full scan of my backup folder and any instances of the old sub directory name. Only then did I realize that the .htaccess file had not been copied and that was the reason why I kept getting a blank page when accessing the wp-admin page. I’ll advise anyone to be aware of this or simply use Filezilla for your file transfers in the first place. (Note that the file transfer will take significantly longer than using an “on-board” file manager, such as the one in cPanel.) Hope this helps someone avert a major headache 🙂
    ~WebDevByAlex

    • Hi Alex,

      When using the web host’s File Manager or a tool like Filezilla, you’ll want to make sure to check the option that says Show Invisible Files. This will allow you to see the .htaccess file.

      In any case, click Save Changes on the Settings > Permalinks page will recreate an .htaccess file for you. But, it might be nice to reference your old .htaccess file in case there were other settings in there you needed to keep.

  5. Thank you for the tutorial!

    One question. I moved the website from a subfolder to root.
    I think I have problem with the: 9 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed. Test the site again in a different browser to be sure the pages are caching correctly.

    1) How do I reset the caching because I hadn’t install caching plugin.
    2) I opened the .htaccess file but I don’t know what to update

    Thank you!

    • Hi! If you are not using a caching plugin, you likely do not have any caching-related settings in the .htaccess file. Some caching plugins (depending on the configuration) will automatically write specific rewrite directives in the .htaccess file for the cached pages. This is not something one would manually modify but would be modified by the plugin after resaving the configuration and being prompted to “Update Mod Rewrite Rules”.

      Since you are not using a caching plugin, this will not apply to you. Though, you may want to go to Settings > Permalinks and click Save Changes as this will automatically update your .htaccess file with the correct permlink (pretty URL) structure.

  6. Hi WP Girl, I had many problems with 404 errors as well as previous posters. I don’t know if it was because it was in a subdir that caused the problem, so I started from scratch and used the instructions from wordpress.

    https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory.

    Changing the wordpress location in step 1 does not occur in this example and seems a bit clearer and safer and will probably avoid 404 errors.

    Just a thought.

    • Hi Michael,

      I have two posts describing two very different processes. The first post is where you don’t actually move WordPress but make a couple settings changes to show the URLs from the root: https://askwpgirl.com/move-wordpress-from-subdirectory-to-root-directory/

      The post you are commenting on is where someone already has their site in a subdirectory and really does want to MOVE it to the root. The WordPress.org article you referenced does not describe this process. It describes a process where someone has their site in the ROOT and wants to MOVE it to a subdirectory or already has it in a subdirectory and wants to show the URLs from the root (which is described in my post https://askwpgirl.com/move-wordpress-from-subdirectory-to-root-directory/). The reason that the WordPress.org tutorial is confusing is most people don’t usually decide in advance that they want to have their site in a subdirectory. What they usually do is use an auto installer that put their site in a subdirectory now they really want to show their URLs from the root and don’t know how.

      With existing sites, you can’t get away from 404 errors if you “move” it from one location to other no matter which direction you go.

      If people are starting out with a NEW site, then installing WordPress in the subdirectory AND following my instructions in https://askwpgirl.com/move-wordpress-from-subdirectory-to-root-directory/ will result in no 404 errors, since you will not have built a bunch of pages with links that now all have to be fixed. So, I think that’s what you are saying.

      I imagine we are on the same page with this but addressing different points in time in the development process, so that’s a good point I should mention!

      Thanks for writing!

      Angela

  7. Angela,

    I wish I had found your site before goofing up! LOL.
    I attempted to move the site from a subfolder to the root and it was a major fail.

    I had to amend the wp-config.php with the define statements that pointed back at the subfolder in order to login, so I’m trying it again.

    I could not change the settings > general > urls. They were greyed out.

    Can you lead me in the right direction from here?

  8. Hi Angela, thanks a lot for this simple (non complicated) but working article. I did a total change of an eCommerce website in a folder and was concerned a lot about moving it to the root. I did some searching and this article was my choice, only that I am much happier after I did the moving accordingly. I only did a couple or three link corrections. Thanks again.

    • Hi Asfaha,

      I’m glad this article worked for you. I noticed that you have a website for learning Tigrigna. My daughter-in-law is from Ethiopia. Is this the same as Tigrinya? I am picking up a few phrases in Amharic.

      Have a nice day and thanks for writing!

      Angela

      • Hi Angela, I’m very glad that you know and are interested in Amharic. My website for learning Tigrigna is a bit different from Amharic. We use the same alphabet and my next project is Amharic. Our alphabet does not use vowel system and the idea is to make it easy to learn the alphabet system (first).

        Thanks for your reply

  9. Please help with this site transfer question..

    I moved all files from aclcnational.org/dev to aclcnational.org (public_html) but when I login to aclcnational.org it redirects to aclcnational.org/dev. I changed the general settings from aclcnational.org/dev to aclcnational.org but it made no difference.

    Please advise

    Thank you.

  10. {{{{{{{hugs}}}}}}}

    you just saved my job <3

    (not really, they wouldn't have fired me. but they would've been angry. now they won't.)

  11. This is really helpful, Angela (WP Girl!)

    Thanks, I am moving one of my installations from sub-directory to root domain, I am not too much worried about SEO for now as I had only started on that blog and made a decision to have wordpress on root domain instead of subdirectory (/blog).

    Cheers!

    Thanks

    • Hi IB, I hear that a lot! I think the codex tends to be a bit confusing on many topics as it’s written as documentation rather than instructional material. Glad this worked for you!

  12. Hello Angela!

    I did all your instructions but Error 403 appears whenever I try to login to admin after I moved the files from the subdirectory to the root. Any help with this? Thank you so much!

    • Hi Arvie,

      Be sure to check the URLs for the site. Since you can’t login, then you will have to go to your web hosting control panel’s phpMyAdmin app and check to make sure the Site and Home URL both use the main domain with no trailing forward slashes.

      Also, you might try checking your .htaccess file and be sure it’s not referencing the subdirectory in the rewrite structure.

      Let me know if you continue to have issues. Is the front end of the site showing okay?

      Angela

  13. Hi,

    Thanks for these instructions. I’m following the last part since I had already pretty much manually recreated the site at a new host and in that process changed most of the links from the subdirectory to the root. The wp install is in the public_html directory.

    What I’m trying to do now is make sure links people had bookmarked and links from other sites will redirect.

    I put the 3 lines you specified at the top of my .htaccess file in the public_html directory, right in front of the WordPress permalinks section, which is the only other stuff in there.

    This still gave me a 404 error for the page I was testing.

    I’m not sure what to check next. The only thing I could think of is that the domain I am using is set up as an add on domain at the new host, since I used a different one while testing.

    Do you have any thoughts?

    Thanks for your help,
    Ami

    • Hi Ami,

      Sorry for the delayed response. I was traveling and just got back. Maybe you can send me a private message so I can check to see what page it is that isn’t working. Are the other page/post redirects working okay?

      Email me via: https://askwpgirl.com/contact/

      Thanks!

      Angela

  14. I encountered a problem with my pages

    The requested URL /contact/ was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  15. Superb articles Angela I have read both now. I have 5 girls in my eCommerce mentoring Group, I will send them the link to your blog, it will be an inspiration to know there is a girl with so much tech knowledge! 🙂 If we use the Duplicator plugin do we still modify the htaccess file so we don’t lose SEO credit?

  16. Hi Angela, I’m preparing to move a new WordPress site from a subdirectory into the root where the current website exists. Your post looks like just the step-by-step instructions I was looking for, but maybe you could help with one other question I had:

    As well as move the new website from its subdirectory to the root, I would like to move the current site from the root into a subdirectory. Would I be able to accomplish this by following your steps, only in the opposite direction (root=>subdirectory)? I imagine I would move the current site out of the root to a new subdirectory first, then move the new site into the root, which would then be empty.

    I’m probably making myself a lot of unnecessary work in keeping the old site live, but I would like to have it there in a pinch in case something goes wrong with the new one. If you can’t tell already I’m pretty new with this…. Thanks!

    • Hi Adam,

      I find the most helpful and easiest way to accomplish this is by using the Duplicator plugin.

      Install the Duplicator plugin on your current site and create a PACKAGE of this site. If that is successful, you can download the package and the install script for the package. Then, you can upload the ZIP file and the installer.php file into a new subfolder called “old” or something like that and run the installer script. Create a new, blank database using the MySQL Database Wizard in your web hosting control panel. Take note of the database location, name, username, and password. Then, visit the folder URL, e.g. mysite.com/old/installer.php. You will be walked through step by step to restore the current site into a subdirectory. This will NOT effect the live site and will be good practice for doing this process on the new site to move it into the root directory.

      You have two choices when “moving” the new site to the root directory, you can move it by packaging it up with the Duplicator plugin and doing the same process as above but in the root (you’ll probably want to delete your old site if you effectively created the duplicate of it as instructed above). OR, you can simply just edit the index.php file in the root directory and change your general settings in the new site to reflect the new location. See detailed instructions for this process at: https://askwpgirl.com/move-wordpress-from-subdirectory-to-root-directory/

      Let me know how it goes, Adam. I would recommend running the Duplicator plugin on both sites to have good backups of each before proceeding.

      • Hi Angela, Thanks for the thorough response! I’ve had some technical issues keep me from transferring the site as of yet but will follow your advice and try out the Duplicator plugin again. I’ve had mixed luck with in the past but it’s probably due to my own mistakes (usually is!)

        • I think the hard thing with the duplicator plugin and others is the web hosting you are trying to move from. It sometimes helps to buy the Pro version, so you can exclude the uploads directory, for example, and download that manually and upload it to new location. Making the archive a manageable size really helps.

  17. THANK YOU, SO, SO MUCH!!! I’ve been working for the last month in a subdomain for a really pain-in-the-ass client. And I was very afraid I couldn’t do it properly. Pretty new to WP.
    But your detailed step by step make me feel safe to do it. So, thank you again! Love your website

    • Hi Micaela, Lol on the pain-in-the-ass client. Last thing you need on go live are major issues! I’m so glad these instructions worked for you, especially since you are new to WP. I teach a lot of beginners, so I try to have “beginner mind” when I write. Take care. Angela

    • That’s so good to hear! It’s not too hard, but there are some details to pay attention to. Please feel free to tweet or share the post. And thanks for letting me know it worked. 🙂

    • I’m glad this worked. Do you have other tutorials you would like to see written that might be confusing or not as detailed elsewhere? I’m pretty up on all the migration stuff, image galleries, SEO, theme customization, and best practices.

  18. Hi,

    I have did the following of your method, but get a 404 page not found issue.
    what did I do wrong or missing something?
    here is my step-by-step:
    1. backup and downloaded files.
    2. remove old site files.
    3. change setting on my WP admin’s setting -> general both url to new one.
    4. move WP files from the subdirectory up one level to the root. ( move from “public_html/main/sub” to “public_html/main” )
    5. login new url’s admin and save permalinks setting.

    After all when I try to visit new url in browser, it still redirect me to old url (http://mywebsite.com.tw/sub),
    and display a 404 not found page.
    but I have already deleted (sub) folder and files in my cPanel.
    should I need to make some change in .htaccess or index.php?

    Any help would be appreciated.
    Thank You!

    • So, are the files in the main folder or public_html?

      What you can do is login to phpMyAdmin via your web hosting control panel and double the URLs for the site in the wp_options table. You can email me privately if you want to send me the URL to your site. https://askwpgirl.com/contact/

      There are a few possibilities for issues:

      1 – There is a typo in one of the URL fields which you can fix in phpMyAdmin.

      2 – The files were moved to the wrong folder.

      3 – The .htaccess is redirecting the site (you can rename the .htaccess file in the File Manager and call it .htaccess-bk)

      4 – Check the index.php file to make sure it doesn’t contain the subdirectory in the require line. The require line should only show:

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

      I would like to help you with this, so I can improve the blog post, so please let me know what you find.

      • Hi,

        I have checked the steps 1, 3 and 4 as you have suggested. everything is fine.
        But not sure if the problem is step 2, how do I check and deal with it?

        I also sent you my backend info privately.
        Thank you for the help again.

        • Hi Walt,

          It seems like you got this resolved but I did notice you still had a copy of the dev site in the subdirectory. Once you can be assured everything is working from the root of the domain, I would get rid of the additional subdirectory install to avoid having that get hacked or indexed by Google for duplicate content.

          Angela

Leave a Reply

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