Back to Community

How to Install WordPress in a Subdirectory and Serve it from the Root Domain

39 threads Sep 16, 2025 CoreInstalling wordpress

Content

Many WordPress users face a common challenge: they want to install WordPress in a subdirectory for development or organizational purposes but have the final site appear to be running from their main domain (e.g., domain.com instead of domain.com/blog). This setup is often used to keep a live site running while a new version is built, or to integrate WordPress with an existing non-WP application. This guide explains the correct way to achieve this.

Why This Setup is Needed

This scenario typically arises in a few situations:

  • You have an existing HTML, Joomla, or vBulletin site in your root directory and want to add a WordPress blog without disrupting the current site.
  • You are developing a new WordPress site on your live server but need to keep the old site accessible until the new one is ready.
  • You want to use a reverse proxy to serve WordPress content from a specialist host through your main domain's subdirectory.

The core of the problem is managing file locations and URL structures so that your content is served from the right place while maintaining correct permalinks, asset loading, and admin functionality.

Recommended Solution: The Official WordPress Method

The safest and most supported method is to use WordPress's built-in capability to live in a subdirectory while serving the site from the web root. This avoids the complexities and potential conflicts of running two applications in the same directory.

Step-by-Step Guide

  1. Install WordPress in a Subdirectory: Upload all WordPress files to a new folder in your public directory, for example, /public_html/newblog/. Complete the standard installation process by visiting yourdomain.com/newblog/wp-admin/install.php.
  2. Update the Site Address: Log into your WordPress admin dashboard (e.g., yourdomain.com/newblog/wp-admin). Navigate to Settings > General. Change the Site Address (URL) to your root domain (https://yourdomain.com). Leave the WordPress Address (URL) as the subdirectory (https://yourdomain.com/newblog). Save the changes. Note: You will be logged out, and trying to visit your root domain at this point will result in an error—this is normal.
  3. Move the index.php File: Using your hosting file manager or FTP, copy (not move) the index.php file from your WordPress subdirectory (/public_html/newblog/index.php) to your root directory (/public_html/index.php).
  4. Edit the Root index.php File: Open the index.php file now in your root directory in a text editor. Find the line that looks like:
    require __DIR__ . '/wp-blog-header.php';
    Change it to point to your subdirectory:
    require __DIR__ . '/newblog/wp-blog-header.php';
    Save the file.
  5. Update Permalinks: Log back into your WordPress admin (at yourdomain.com/newblog/wp-admin). Go to Settings > Permalinks and simply click "Save Changes" without making any modifications. This refreshes your rewrite rules and ensures your pages and posts will have the correct URLs from the root domain.

Your site should now be fully functional at the root domain (yourdomain.com), while all the core WordPress files remain neatly organized in the subdirectory.

Important Considerations and Alternative Scenarios

  • Reverse Proxy Setup: If you are using a reverse proxy (as mentioned in Thread 1 and Thread 2), the method above may not be sufficient. In a proxy setup, WordPress is often on a completely different server. You must also define WP_HOME and WP_SITEURL in your wp-config.php file to force WordPress to use the public domain URL for generating all links, preventing them from pointing to the internal host.
  • Keeping Old Files: If you need to preserve specific old files or folders (e.g., an /images/ directory with legacy links), you can simply leave them in the root directory. WordPress's rewrite rules are designed to first check if a file or directory exists physically before routing the request through WordPress, so your old links should continue to work.
  • What Not to Do: Avoid installing two separate WordPress installations in the root and a subdirectory. This can lead to significant conflicts with .htaccess rules, database prefixes, and overall management. Migrating a single installation is a cleaner long-term solution.

By following this guide, you can seamlessly integrate a WordPress site into your existing website structure, providing a smooth experience for your visitors without compromising on functionality during the transition.

Related Support Threads Support