Sometimes, you may want to install WordPress in a subdirectory (e.g., /mywebsite
) instead of the root (wwwroot/public_html
), while still serving your site from the root domain (e.g., http://example.com
).
This helps you keep the root directory clean without cluttering it with WordPress files.
👉 Example: Install WordPress in example.com/mywebsite
, but access the site at http://example.com
.
Here’s how you can achieve this:
Create the folder where you want WordPress installed.
For this tutorial, we’ll use:
/mywebsite
Go to your WordPress Dashboard → Settings → General.Update the following:
WordPress Address (URL): http://example.com/mywebsite
Site Address (URL): http://example.com
💾 Save changes.
Move your WordPress core files to the new subdirectory (/mywebsite
).
Copy (do not move) index.php
and .htaccess
from /mywebsite
to your root (wwwroot/public_html
).
If you are on Windows hosting, move web.config
instead of copying.
📌 Note: .htaccess
is hidden. Enable “show hidden files” in FTP or cPanel File Manager.
Open the index.php file in your root folder and find this line:
<div style="text-align:center; margin:20px 0;"> <pre style="display:inline-block; background:#f4f4f4; padding:12px 18px; border-radius:6px; font-size:14px; border:1px solid #ddd;"> require( dirname( __FILE__ ) . '/wp-blog-header.php' ); </pre> </div>
Replace it with this (update with your subdirectory name):
<div style="text-align:center; margin:20px 0;"> <pre style="display:inline-block; background:#f4f4f4; padding:12px 18px; border-radius:6px; font-size:14px; border:1px solid #ddd;"> require( dirname( __FILE__ ) . '/mywebsite/wp-blog-header.php' ); </pre> </div>
Your WordPress is now installed in /mywebsite
but served from http://example.com
.
Keep your root clean while still running WordPress from the subdirectory.
Always clear cache and reset permalinks after making these changes.