Web Site Hosting Tips

Moving your main site to a subdirectory

Moving main site to a subdirectory

Most web hosting providers require you to place your main domain at the root of your hosting directory.

This may be fine for a domain with no subdomains, however, typically subdomains are housed in a subdirectory off of your root leading your main site to be full of your content and any subdomains created. This can lead to an unmanageable directory structure.

The solution is to place your main domain site into a subdirectory. ex. mainsite.

To accomplish this requires an .htaccess file in the root that will redirect to the subdirectory. Add to or create a .htaccess file containing the following:

#RewriteEngine On
#RewriteCond %{HTTP_HOST} ^(www.)?thechamberlands.net$
#RewriteRule ^(/)?$ wpthechamb [L]
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the root folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change YOURDOMAIN to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?YOURDOMAIN$
# Change 'YOURDIRECTORY' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/YOURDIRECTORY/
# Don't change these line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'YOURDIRECTORY' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /YOURDIRECTORY/$1
# Change YOURDOMAIN to be your main domain again.
# Change 'YOURDIRECTORY' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?YOURDOMAIN$
RewriteRule ^(/)?$ YOURDIRECTORY/index.php [L]