Sometimes, you want to install WordPress in the root (wwwroot/public_html) directory but without filling up the root directory with WordPress files and folders. In this situation, you can give the WordPress website its directory so that WordPress will be installed in a subdirectory, and your website will be served from the root folder.
To put it simply, you can install WordPress in the example.com/mywebsite directory, and still, you can access your website with the URL http://mywebsite.com.
Let's see how we can go about it with these simple steps –
1. First, create a folder where you want to install WordPress.
In this tutorial, we will use /mywebsite.
2. Now, in the WordPress dashboard, navigate to Settings >> General Settings.
3. In the WordPress address (URL) box, change the address to a new location of your main WordPress core files.
For example, http://example.com/mywebsite.
4. In the box Site address (URL), change the address to the root directory URL.
For example, http://example.com and click on Save Changes.
5. Move your WordPress core files to the new location (/mywebsite folder).
6. Now Copy (do not Move) index.php and .htaccess files from /mywebsite folder to the root directory, i.e., wwwroot/public_html.
7. By default, the .htaccess file would be invisible. Hence, set the FTP client to show hidden files.
If you are using the cPanel file manager, check the show hidden files checkbox while you access the file manager.
Note: If you do not use Pretty Permalinks, you may not have a .htaccess file.
If you are running WordPress on a Windows (IIS) server, you will have a web.config rather than a .htaccess file.
8. For the index.php file, instructions remain the same.
Copy (do not Move) the index.php file to your root directory.
9. For the web.config file, move (do not Copy – the exact opposite of .htaccess) it to your root directory.
10. Open the root directory's index.php file in a text editor.
11. Replace line –
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
with the following line and placing your subdirectory name as follows –
require( dirname( __FILE__ ) . '/mywebsite/wp-blog-header.php' );
12. Browse and log in to the new WordPress dashboard - http://example.com/mywebsite/wp-admin/.
13. If you have set up Permalinks, update the Permalink structure -
In the WordPress dashboard, navigate to Settings >> Permalinks Settings, check the checkbox of the permalinks setting you set previously, and Save the changes.
→ Looking to change the document root folder using .htaccess?
Please refer to the Change document root in .htaccess for more details.