This is one of the most asked questions that beginners / non programmers ask when hosting a wordpress website. By default installing a WordPress et up through cpanel on the main domain does a WordPress installation in the public_html or the root directory.  This  works great if only a single website is to be hosted out of this space. However this is rarely the case and we generally add several domains through the Addon domains feature in the cpanel or in other cases would want to create staging/demo website for the same domain.

In such a case it is always better to have a separate folder for each of your website including the root domain. The following steps illustrate how you can move your wordpress installation on main domain inside a subfolder.

Step 1: Move all files and folders from your root directory to a subdirectory.

Step 2: Create .htaccess file in the root directory and edit as follows. Remember to replace example.com and my_subdir with your own variables as required.

 

				
					<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L] 
</IfModule>
				
			

Step 3: Edit the .htaccess inside the sub folder as follows:

				
					<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
				
			

Leave a Reply

Your email address will not be published.