Nov 19th, 2012
Updated July 17th, 2016
This is for Hostmonster and Bluehost but will probably work on other shared hosting environments.
The code snippet below is for the main .htaccess file in the /public_html folder.
# Hostmonster.com # .htaccess main domain to subdirectory 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. # # Enables rewriting # Do not change this line RewriteEngine on # Proceeds if the http host is www.yourmaindomain.com or yourmaindomain.com # Change yourdomain.com to be your main domain. RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ # Proceeds if the URI does not (!) start with (^) /subdirectory/ # Change 'subdirectory' to be the directory you will use for your main domain. RewriteCond %{REQUEST_URI} !^/subdirectory/ # Proceeds if the URI is not an actual file or directory # So, if you leave files and directories in the root directory that have the same names as ones found in the subdirectory, the root directory will be used # Don't change this line. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # If all of the above conditions are met, then use the subdirectory but don't reveal what's going on to the end user # Change 'subdirectory' to be the directory you will use for your main domain. RewriteRule ^(.*)$ subdirectory/$1 # Proceeds if the http host is www.yourmaindomain.com or yourmaindomain.com # Change yourdomain.com to be your main domain again. RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ # If the request is for the root of the domain, either with or without the trailing slash, load up index.htm from the subdirectory without letting the end user know what's happening # Change 'subdirectory' 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. RewriteRule ^(/)?$ subdirectory/index.php [L]
You'll need to update a line in settings.php:
- Change the $base_url so that it has the full domain, for example:
$base_url = "http://www.burningtokenrecords.com"; // NO trailing slash!
Finally, you'll need to update the .htaccess file in the root of the Drupal directory:
- Uncomment the following line:
RewriteBase /
- Change
RewriteRule ^ index.php [L]
toRewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Further Reading on .htaccess rules:
Here's the explanation of the rewrite rules as I understand them. A good list of references I found is located here: http://httpd.apache.org/docs/current/rewrite/ and a very good read that told me most of what I need to know about the above .htaccess rule, Introduction to regular expressions and mod_rewrite, is located here: http://httpd.apache.org/docs/current/rewrite/intro.html