I am using web hosting service of hostmonster.com to run a drupal site. The hosting service requires all web files reside within \public_html.

I used a primary domain to sign in the hosting service, which by default points to the root folder \public_html.

I can add other domain to the hosting and point it to a sub-folder \public_html\####

I am using my primary domain to run a Drupal site, so all drupal files, including .htaccess, reside in \public_html. Now the problem is the .htaccess prevent from visiting any sub-folder \public_html\####, so my additionally added domains are all blocked.

My question is: how to modify the default drupal .htaccess such that only drupal files are blocked from direct visit, and all subfolders of other domains are not blocked.

(1) My hosting service does not allow the primary domain to point to a subfolder within \public_html.
(2) I know I can create a subfolder for it and use redirect with .htaccess. However, the problem is URLs of all links on the site contain the sub-folder name, which s not what I need. SO, I have to put my primary domain drupal files in root folder \public_html


huayen’s picture

The hostmonster.com knowledgebase provide following tips:

.htaccess - How to make a subfolder the main folder for your main domain

The main domain on the hosting account uses the public_html folder for all of its Web site files. Any addon domains use subfolders inside the public_html folder. In order to also set up your main domain to use a subfolder on your hosting account you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your main domain will be redirected to a subfolder on public_html.

Visitors to your Web site will not be able to tell that your main domain is using a subfolder, they will still see the Web site address as http://www.yourdomain.com/page.html


# Hostmonster.com
# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.

RewriteEngine on

# Change yourdomain.com to be your main domain.

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Change 'subfolder' to be the folder you will use for your main domain.

RewriteCond %{REQUEST_URI} !^/subfolder/

# Don't change this line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.

RewriteRule ^(.*)$ /subfolder/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder 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.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]


This redirect does work, but all links in Drupal site still contains the sub-folder name. Also, the created URL_alias has to contain the subfolder name.

huayen’s picture

Solved by modifying $base_directory in setting.php

nevmoor’s picture

Could you be more specific about HOW you did the mod to $base_directory??
I would like to redirect to a subdomain which contains a redesign of my site.