These instructions lay out in brief the considerations for setting up a subdomain site in the form available at EngineHosting, where all domain accesses go to the main domain public_html. On other hosts which use DNS to assign subdomains, you won't need the additions to the main domain .htaccess.
The EE install, where you have CP themes, etc., is at the root
directory for web service: public_html. It is important that it stay
there, because of a change Ellis made in EE that broke updating capability from
subdirectories. However, you can freely move the system folder where
you like, adjusting your index.php
path. I have it above
public_html, in the usual fashion.
Here’s the htaccess scripting that I use to enable a subdomain on a
subdirectory of public_html. YMMV, but this is straightforward, and
again not needed if your host directly assigns subdomain directories.
In root .htaccess, above your scripting for the EE install there, and
below RewriteEngine On, goes the following. It accomplishes redirecting subdomain
web requests so that they appear to be direct on the subdirectory:
# add the www if toplevel.com only; tell the browser always to use it
RewriteCond %{HTTP_HOST} ^(yoursite.*) [NC]
RewriteRule ^http://www\.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# pick off any subdomains to be handled in their own directory
RewriteCond %{HTTP_HOST} ^subdomain.yoursite.com [NC]
RewriteCond %{REQUEST_FILENAME} !subdomain/ # allows image requests etc. to pass through
RewriteRule ^(.*)$ ae/$1 [L]
In the subdomain’s subdirectory, you just put your standard .htaccess
as if it were a top-level domain. In EE itself, be sure to check through the main
level site’s CP path settings, just to make sure the installer was
sensible. I find Deeploy Helper to be very helpful to assure such matters,
besides its primary purpose.
You can initialize the subdirectory EE by copying over your main
level’s index.php, adminasyounameit.php, and anything like
favico or images directories that you want to use on the subdomain.
As an EE site, the subdomain is independent of the domain-level site.
Here are the additions or changes I made to the results of such a copy:
In adminasyounameit.php, set your system path relative to the subdirectory:
$system_path = '../../de/system'; // for system in de folder above public_html
Now you can run admin normally from the subdomain website. There are probably tricks to get it to line up on the correct template group; haven’t bothered.
In index.php, also:
$system_path = '../../de/system'; // for system in de folder above public_html
This is what fundamentally enables your site
Now you want to set so correct template group is used for the subdomain. Must set initial template too, as created bugs here were resolved.
$assign_to_config['template'] = 'index';
$assign_to_config['template_group'] = 'subtemplategroup';
You likely want a separate 404 page for the subdomain; otherwise will get main domain’s
$assign_to_config['site_404'] = 'subtemplategroup/notfound';
The following form is handy if you do as I do, use global variables inside to site-specifically target generic templates to localize for many purposes
$assign_to_config['global_vars']
= array("my_channel" => "subdomainchan", "my_template_group" => "subtemplategroup");
Set the site name so it shows correctly wherever defaulted
$assign_to_config['site_name'] = 'SubDomain Sitename’;
Let EE internals know where this subdomain is in the web url sense. This is crucial in having it emit items correctly which have paths auto-added, such as may be case for css, images, etc..
$assign_to_config['site_url'] = 'http://subdomain.yoursite.com/';
The CP theme will be handled automatically from what you config’d in the base EE install control panel, as the CP will be called just as if it were from the main site.
We are now just above ‘END OF USER CONFIGURABLE SETTINGS’ in index.php, and things should run on the subsite, once saving from here.
I hope this is quite readable if not perfectly formatted, after a bit of a fight with the StackExchange editor about indents vs. code blocks.