Host your Drupal in a sub-directory at Bluehost

By xngo on February 19, 2019


In a normal Drupal installation, you put the code in DOCUMENT_ROOT directory and be done with it. Everything is nice and rosy.

However, I would to like to host multiple version of Drupal using subdomain. I want to clearly separate different version using different directories. For example,

  • => public_html/d7
  • => public_html/d8

Setup for

  1. Log in to your Bluehost account. Go to domains->subdomains and your subdomain.
  2. public_html/d7 directory will be created. Put your Drupal 7 in there.
  3. Wait for a few minutes for the subdomain to take effect. That is it. It is that simple.

Setup for is a pain

Redirecting all traffic to public_html/d8 is a pain. It took me 3 days to try out different combinations of settings from 3 different places:

  • public_html/.htaccess
  • public_html/d8/.htaccess
  • public_html/opw/sites/default/settings.php

At first, Clear all cache and wait for a couple of minutes for every changes is not helpful. Neither does using Chrome in incognito mode because it behaves differently between different computers. Here are the symptoms that I encountered:

  • As an Admin, mouse hover links show different parent path for admin links and content links.
  • Different parent path for Authenticated user and Admin user.
  • Random display of blank page with text Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.
  • It worked yesterday but not today. I haven't change anything.( I started from the good path. All successive testing is good until the next day ).

After the 3rd day, I came to the conclusion that there is an issue with Drupal. It doesn't handling ??request path?? consistently. I'm gladly able to vent through this post. It puts my frustration at ease.


In public_html/.htaccess, redirect all traffic to public_html/d8.

# Use PHP70CGI as default
AddHandler fcgid70-script .php
RewriteEngine On
RewriteRule ^$ d8/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ d8/$1 [L]

In public_html/opw/sites/default/settings.php, at the following code at the bottom:

if (isset($GLOBALS['request']) and '/d8/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {  
  $GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');


As of now, what were tested:

  • Links in the content and header area work for Authenticated user and Administrator.
  • Ajax call are working.
  • File upload is working.

Pending issues

  • Install modules from the UI doesn't work. It shows permission denied.


About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.