How to Move WordPress from Root Directory to Subdirectory

October 22, 2024 / WordPress

This article explains how to move WordPress from the root directory to the subdirectory.

At times, you might want to install WordPress in the root directory (wwwroot/public_html) but choose not to mess it with WordPress files and folders. Under these circumstances, you can set up a subdirectory for your WordPress installation while still helping your website from the root folder.

For instance, you can install WordPress in the directory “sample.com/mywebsitee” and access your site through the URL “http://mywebsitee.com”.

Here’s how to do it in a few simple steps:

  1. Create a Subdirectory:
    Start by creating a folder where you want to install WordPress. In this tutorial, we will use “/mywebsitee”.
  2. Update General Settings:
    In your WordPress dashboard, go to Settings >> General Settings.
    settings>general
  3. Change WordPress Address:
    In the WordPress Address (URL) box, update it to the new location of your main WordPress core files (e.g., http://sample.com/mywebsitee).
  4. Set Site Address:
    In the Site Address (URL) box, change it to the root directory URL (e.g., http://sample.com) and click “Save Changes”.
    URL
  5. Move WordPress Core Files:
    Move your WordPress core files to the new location “/mywebsitee” folder.
  6. Copy Important Files:
    Copy (do not move) the “index.php” and “.htaccess” files from the “/mywebsitee” folder to the root directory (i.e., wwwroot/public_html).
  7. Show Hidden Files:
    By default, the “.htaccess” file may be hidden. Make sure your FTP client is set to show hidden files. If you are using cPanel’s file manager, check the box to show hidden files.

    show hidden files

    Note: If you are not using Pretty Permalinks, you may not have a “.htaccess” file. If you are on a Windows (IIS) server, you will have a “web.config” file instead.

  8. Handle the index.php File:
    Copy (do not move) the “index.php” file to your root directory.
  9. Move the web.config File:
    For the “web.config” file, move (do not copy) it to your root directory.
  10. Edit the index.php File:
    Open the “index.php” file in the root directory with a text editor.
  11. Update the Require Statement:
    Replace this line:

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

    With the following line, insert your subdirectory name:

    require( dirname( __FILE__ ) . '/mywebsitee/wp-blog-header.php' );
  12. Access the New Dashboard:
    Browse to the new WordPress dashboard at “http://sample.com/mywebsitee/wp-admin/” to log in.
  13. Update Permalink Structure:
    If you have set up Permalinks, go to “Settings >> Permalinks Settings” in the WordPress dashboard, select your previous permalink structure, and click “Save Changes.”
    permalinks

That is it! Hope you liked our article. If you require additional support, seek help from our support staff.

Spread the love