Fixing Common Issues When Installing WordPress in a Subdirectory
Content
Installing WordPress in a subdirectory is a common practice for creating test sites, adding a blog section, or running a separate application alongside a main website. However, this setup often leads to a specific set of problems that can prevent a successful installation or cause the site to malfunction. Based on community reports, this guide covers the most frequent issues and how to resolve them.
Why These Problems Happen
The core of these issues typically lies in server configuration. When WordPress is placed in a subfolder (e.g., example.com/subfolder/), the web server must be correctly configured to recognize that directory as a valid application root and to process PHP files properly. Conflicts often arise from missing files, incorrect .htaccess rules, or permalink settings that clash with rules in the website's root directory.
Common Issues and Their Solutions
1. 404 Errors or File Listing Instead of the WordPress Installer
Problem: Navigating to your subdirectory (e.g., example.com/subfolder/) results in a "404 Not Found" error or a generic list of files instead of launching the WordPress installation script.
Solution:
- Verify PHP is Installed: A 404 error on all PHP files (like
install.php) indicates PHP is not running on the server for that location. Confirm with your hosting provider that PHP is active and properly configured for your subdirectory. - Check for Required Files: Ensure the
index.phpfile is present in your WordPress subdirectory. This file is essential for bootstrapping WordPress. - Correct .htaccess Placement: The
.htaccessfile for WordPress must be located inside the subdirectory, not the website's root. A common mistake is placing it in the wrong location. - Re-upload WordPress: If files are missing or corrupted, delete the subdirectory's contents and perform a fresh upload of the WordPress files from the official website.
2. Admin Login Redirects to the Wrong Location or Main Site
Problem: Attempting to access example.com/subfolder/wp-admin/ redirects you to the main site's homepage or its 404 page.
Solution:
- Root .htaccess Conflict: An
.htaccessfile in your website's root directory can contain rewrite rules that interfere with requests to the subdirectory. Temporarily rename the root.htaccessfile to test if it resolves the redirect. If it does, you will need to carefully merge the rewrite rules. - Confirm Site URLs: Double-check that both the WordPress Address and Site Address in Settings > General correctly point to the subdirectory URL (e.g.,
http://example.com/subfolder). - Resave Permalinks: Navigate to Settings > Permalinks and simply click "Save Changes" to flush the rewrite rules. This often resolves incorrect redirects.
3. Permalinks or Pages Return a 404 Error
Problem: The WordPress homepage in the subdirectory loads, but clicking on any post or page link results in a 404 error.
Solution:
- Subdirectory .htaccess: Ensure the
.htaccessfile within your WordPress subdirectory contains the correct mod_rewrite rules. The standard WordPress rules are:RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /subfolder/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subfolder/index.php [L]Note: Replace/subfolder/with the actual name of your directory. - Server Configuration: For IIS servers, you may need to install a URL Rewrite module and import WordPress rules. For Nginx, the server block configuration must include a specific
locationblock for the subdirectory that handles PHP processing.
4. The Main Site's Index Page Shows Instead of WordPress
Problem: You want your main domain (e.g., example.com) to display the WordPress site installed in a subdirectory, but it still shows the original index file (e.g., index.html).
Solution:
- Index Directive: The web server prioritizes
index.htmloverindex.phpby default. You can often change this priority in your server configuration or via.htaccessusingDirectoryIndex index.php index.html. - Root .htaccess Redirect: To forward all traffic from the root to the subdirectory while keeping the main domain in the address bar, you can use rules like these in your root
.htaccessfile:RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteCond %{REQUEST_URI} !^/subfolder/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /subfolder/$1 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteRule ^(/)?$ subfolder/index.php [L]Note: This is an advanced technique and may require adjustment for your specific setup.
Final Checklist
- All WordPress files are uploaded to the subdirectory.
- The
wp-config.phpfile is correctly configured with the right database details. - The subdirectory has its own
.htaccessfile with the correct mod_rewrite rules. - The WordPress Address and Site URL in the General Settings are accurate.
- Permalinks have been resaved after installation.
- Your server (Apache, Nginx, IIS) is configured to process PHP files in the subdirectory.
If you continue to experience problems, the specific details of your server environment (e.g., Apache vs. Nginx, Windows IIS) are critical for finding a solution. Searching for your specific web server software along with "WordPress subdirectory" will often yield more targeted advice.
Related Support Threads Support
-
Temp index.html page / View WP site while developinghttps://wordpress.org/support/topic/temp-index-html-page-view-wp-site-while-developing/
-
Unable To Install WordPress on subfolderhttps://wordpress.org/support/topic/unable-to-install-wordpress-on-subfolder/
-
WordPress on Windows (with IIS and ASP.NET site)https://wordpress.org/support/topic/wordpress-on-windows-with-iis-and-asp-net-site/
-
Instalación WordPress en mi subdominiohttps://wordpress.org/support/topic/instalacion-wordpess-en-mi-subdominio/
-
I’ve created form on custom page its action generate 404 page in wp?https://wordpress.org/support/topic/ive-created-form-on-custom-page-its-action-generate-404-page-in-wp/
-
host wordpress on IIS as virtual application / directoryhttps://wordpress.org/support/topic/host-wordpress-on-iis-as-virtual-application-directory/
-
should we install wordpress on subdomain?https://wordpress.org/support/topic/should-we-install-wordpress-on-subdomain/
-
Installing WordPress in subdirectoryhttps://wordpress.org/support/topic/installing-wordpress-in-subdirectory-2/
-
htaccess in subdirectoryhttps://wordpress.org/support/topic/htaccess-in-subdirectory/
-
Word press installed on sub domainhttps://wordpress.org/support/topic/word-press-installed-on-sub-domain/
-
Install new WP in subdirectory, cannot complete due to 404 error at URLhttps://wordpress.org/support/topic/install-new-wp-in-subdirectory-cannot-complete-due-to-404-error-at-url/
-
Installation of WP 5.3.2 in Subdomainhttps://wordpress.org/support/topic/installation-of-wp-5-3-2-in-subdomain/
-
htaccess while wordpress is hosting in subfolderhttps://wordpress.org/support/topic/htaccess-while-wordpress-is-hosting-in-subfolder/
-
Installing WordPress With Clean Subversion Repositorieshttps://wordpress.org/support/topic/installing-wordpress-with-clean-subversion-repositories/
-
issue with the installation of wordpress in k8s with subdirectoryhttps://wordpress.org/support/topic/install-wordpress-in-k8s-with-subdirectory/
-
Install wordpress in a subfolder of another wordpresshttps://wordpress.org/support/topic/install-wordpress-in-a-subfolder-of-another-wordpress/
-
Folder in root called ‘(domainname)-redirect’https://wordpress.org/support/topic/folder-in-root-called-redirect/
-
Installing wordpress in subfolderhttps://wordpress.org/support/topic/installing-wordpress-in-subfolder/
-
404 – File or directory not found on WordPress installationhttps://wordpress.org/support/topic/404-file-or-directory-not-found-on-wordpress-installation/
-
wp-admin (under subfolder) Not working beacause of .htaccess (on root folder)https://wordpress.org/support/topic/wp-admin-under-subfolder-not-working-beacause-of-htaccess-on-root-folder/
-
Automatic setup not workinghttps://wordpress.org/support/topic/automatic-setup-not-working/
-
Help with root ,htaccess to send to the WP site in sub dirhttps://wordpress.org/support/topic/help-with-root-htaccess-to-send-to-the-wp-site-in-sub-dir/
-
Install in sub directoryIhttps://wordpress.org/support/topic/install-in-sub-directoryi/
-
Installing second wordpress next to existing onehttps://wordpress.org/support/topic/installing-second-wordpress-next-to-existing-one/
-
Installing WP on Subfolder and Different Hosthttps://wordpress.org/support/topic/installing-wp-on-subfolder-and-different-host/
-
installing wp on domain or subdomainhttps://wordpress.org/support/topic/installing-wp-on-domain-or-subdomain/
-
open a page on a subdomainhttps://wordpress.org/support/topic/open-a-page-on-a-subdomain/