
I just spent a few hours dealing with this.
I am posting this because it might be useful for others.
This is a brand new D7 site.
I have a server set up that uses add on domains.
There is the main domain for the server (which is the public_html directory) and the add on domains are placed in it. I hate this set up.
My set up used to have has this structure:
public_html (yourdomain.com) -- main domain
- yourdomain-1.com
- yourdomain-2.com
Now it has this structure:
public_html
.htaccess makes
- yourdomain.com -- main domain
- yourdomain-1.com
- yourdomain-2.com
The way to accomplish this it is to beg your tech support to set it up or use the information below.
You set up the directory structure. Then create an .htaccess file in the top level of your public_html directory using the code below. The usage is explained well by its creator.
But this is problematic with the D7 installation.
This is from http://support.lunarpages.com/knowledge_bases/article/549
.htaccess How to make a subfolder the main folder for your primary domainThe primary 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 primary 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 primary domain is using a subfolder, they will still see the Web site address as http://www.yourdomain.com/page.html
Solution
# lunarpages.com
# .htaccess primary 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 primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourprimarydomain.com$
# Change 'subfolder' to be the folder you will use for your primary 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 primary domain.
RewriteRule ^(.*)$ /subfolder/$1
# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary 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 works very well but it creates a problem when you try to get the .htaccess file in Drupal 7 to redirect yourdomain.com to www.yourdomain.com.
When you un-comment these lines in the .htaccess file:
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The url gets written in a crazy way.
When you try www.yourdomain.com in a browser, you go to www.yourdomain.com
This is good.
When you try yourdomain.com in a browser, you go to www.yourdomain.com/subfolder/index.php
This is not good.
I tried commenting out the #RewriteBase /
line in the Drupal .htaccess file.
No luck with that.
At last I had an "AHAA!" moment.
I modified the .htaccess file in the public_html folder so that it had a 301 redirect at the very top and leaving the rest of the code alone. Works like a charm.
There are probably smarter ways of doing this, but it works for me.
You also need to set the base url of your site in the settings.php file.
$base_url = 'http://www.yourdomain.com'; // NO trailing slash!
The code below should work for the .htaccess file in the top level of your public_html directory.
# this rule adds redirects yourdomain.com to www.yourdomain.com
# mod_rewrite in use
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
# lunarpages.com use this set up as does bluehost, hostmonster and lots more I imagine
# .htaccess primary 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 primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
# Change 'subfolder' to be the folder you will use for your primary 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 primary domain.
RewriteRule ^(.*)$ /subfolder/$1
# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ subfolder/ [L]