How to Install WordPress in a Subdirectory and Serve it from the Root Domain
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
- 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 visitingyourdomain.com/newblog/wp-admin/install.php. - 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. - Move the index.php File: Using your hosting file manager or FTP, copy (not move) the
index.phpfile from your WordPress subdirectory (/public_html/newblog/index.php) to your root directory (/public_html/index.php). - Edit the Root index.php File: Open the
index.phpfile 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. - 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_HOMEandWP_SITEURLin yourwp-config.phpfile 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
-
From subdomain to root (no wordpress on root)https://wordpress.org/support/topic/from-subdomain-to-root-no-wordpress-on-root/
-
Changing files directory outside the WP installationhttps://wordpress.org/support/topic/changing-files-directory-outside-the-wp-installation/
-
Installing a parallel WordPress site on Bluehosthttps://wordpress.org/support/topic/installing-a-parallel-wordpress-site-on-bluehost/
-
Is it possible to add WordPress Blog to a Joomla Website?https://wordpress.org/support/topic/is-it-possible-to-add-wordpress-blog-to-a-joomla-website/
-
How to host a wordpress blog on a subdirectoryhttps://wordpress.org/support/topic/how-to-host-a-wordpress-blog-on-a-subdirectory/
-
install a WordPress without conflict via current CMShttps://wordpress.org/support/topic/install-a-wordpress-without-conflict-via-current-cms/
-
Looking to fix the website main page linkhttps://wordpress.org/support/topic/looking-to-fix-the-website-main-page-link/
-
Help with relative paths after migrationhttps://wordpress.org/support/topic/help-with-relative-paths-after-migration/
-
How-to guide for using an admin subdomain?https://wordpress.org/support/topic/how-to-guide-for-using-an-admin-subdomain/
-
WordPress installed in sub directory – category in childhttps://wordpress.org/support/topic/wordpress-installed-in-sub-directory-category-in-child/
-
Changing subdomain to subdirectoryhttps://wordpress.org/support/topic/changing-subdomain-to-subdirectory/
-
2 questions about staging siteshttps://wordpress.org/support/topic/2-questions-about-staging-sites/
-
Running WordPress with vBulletinhttps://wordpress.org/support/topic/running-wordpress-with-vbulletin/
-
Installing wordpress into the same directory as existing static html websitehttps://wordpress.org/support/topic/installing-wordpress-into-the-same-directory-as-existing-static-html-website/
-
Installing WordPress on a subdomain of an existing online storehttps://wordpress.org/support/topic/installing-wordpress-on-a-subdomain-of-an-existing-online-store/
-
Coexistence of HTML and WPhttps://wordpress.org/support/topic/coexistence-of-html-and-wp/
-
From Joomla to WordPresshttps://wordpress.org/support/topic/from-joomla-to-wordpress-4/
-
Proxied Installationhttps://wordpress.org/support/topic/proxied-installation/
-
Installing WP but keep old Foldershttps://wordpress.org/support/topic/installing-wp-but-keep-old-folders/
-
Migrating html to wordpress: what is the “go live” step?https://wordpress.org/support/topic/migrating-html-to-wordpress-what-is-the-go-live-step/
-
Is it possible to move “posts” within a databasehttps://wordpress.org/support/topic/is-it-possible-to-move-posts-within-a-database/
-
Migrating from Joomla, articles or pages ?https://wordpress.org/support/topic/migrating-from-joomla-articles-or-pages/
-
Sub directory install going livehttps://wordpress.org/support/topic/sub-directory-install-going-live/
-
Moving a WordPress Sitehttps://wordpress.org/support/topic/moving-a-wordpress-site-2/
-
Rebuilding WP as a stating site on different domainhttps://wordpress.org/support/topic/rebuilding-wp-as-a-stating-site-on-different-domain/
-
A second install in a new folderhttps://wordpress.org/support/topic/a-second-install-in-a-new-folder/
-
Two WordPress installs vs. Moving WordPress install locationhttps://wordpress.org/support/topic/two-wordpress-installs-vs-moving-wordpress-install-location/
-
Install WP on subfolder /blog in an existing URL /bloghttps://wordpress.org/support/topic/install-wp-on-subfolder-blog-in-an-existing-url-blog/
-
Joomla to WordPresshttps://wordpress.org/support/topic/joomla-to-wordpress-17/
-
WordPress Subdirectory Post url to main urlhttps://wordpress.org/support/topic/wordpress-subdirectory-post-url-to-main-url/
-
What happens after the Pretty Permalink changes?https://wordpress.org/support/topic/what-happens-after-the-pretty-permalink-changes/
-
give domain to local wordpresshttps://wordpress.org/support/topic/give-domain-to-local-wordpress/
-
settting up a webserverhttps://wordpress.org/support/topic/settting-up-a-webserver/
-
Migrating sub domainhttps://wordpress.org/support/topic/migrating-sub-domain/
-
Installation folderhttps://wordpress.org/support/topic/installation-folder-2/
-
Re-installing on a new server without SSL certificateshttps://wordpress.org/support/topic/re-installing-on-a-new-server-without-ssl-certificates/
-
Moving website from sub directory to main directoryhttps://wordpress.org/support/topic/moving-website-from-sub-directory-to-main-directory/
-
Multisite setup .htaccess question.https://wordpress.org/support/topic/multisite-setup-htaccess-question/
-
How to make the subdirectory look like main blog?https://wordpress.org/support/topic/how-to-make-the-subdirectory-look-like-main-blog/