2

I'm running multiple domains/sites with one EE install without using MSM (I don't need the power or complexity and to save licence fees). I have copied the index.php file to the subsidiary domain and edited the Custom Config Values as per instructions.

$assign_to_config['template_group'] = 'ocoach';
$assign_to_config['template'] = 'index';
$assign_to_config['site_index'] = 'http://www.xyz.co.uk';
$assign_to_config['site_404'] = 'ocoach/404';

I want to have url's like:
domain.co.uk/item/url_title
domain.co.uk/category/category_url_title

I've created a template group called ocoach and templates within in called, index, item, category, 404. I've got seg2cat installed. But I get the 404 page when I use either of the above url's. If I go in and tick the "Make the index template in this group your site's home page?" it all works. But if I want to have multiple domains using different template groups I can't set the default in the EE control panel. I thought that setting it in the index.php file in each domain would override the control panel, but it doesn't seem to make it the default, just the one to use. I've searched around and can't find mention of setting the "default_template_group" as a config variable.

3

You've probably already done some of this, but I'm providing you my process of doing subsites, under EE2 without Multi-Site Manager (MSM).

In the subsite folder's index.php file, I set the following…

/* -- Multiple Site Manager --  */
$assign_to_config['site_name']  = 'subsite';
$assign_to_config['cp_url'] = 'http://subsite.org/admin.php';
$assign_to_config['site_url'] = 'http://subsite.org';

and then

/* -- CUSTOM CONFIG VALUES --  */
$assign_to_config['template_group'] = 'subsite';
$assign_to_config['template'] = 'index';
$assign_to_config['site_index'] = '';
$assign_to_config['site_404'] = '';
$assign_to_config['global_vars'] = array(
    'subsite_id' => 'subsite',
    'domain' => 'http://subsite.org',
    'site_name' => 'My Subsite',
    'googleSearchToken' => 'token',
    ); // This array must be associative

Then in config.php I change the following

/* -- URI PROTOCOL --  */
$config['uri_protocol'] = "AUTO";

to

$config['uri_protocol'] = "PATH_INFO";

This last switch is a pretty big deal on most of the servers I work on for getting subsites to work properly. I've only worked on our development server without having to switch to 'PATH_INFO' on all our production servers seem to require it.

The other items seem to be more, as you need them. For example, we don't always allow logging in via the sub site, so mostly the cp_url points to the main domain.

$assign_to_config['cp_url'] = 'http://main-domain.org/admin.php';

we always have a few global_vars but many sites have none, etc. But the adjustment in the config.php file, seems to be the key component to make everything work.

| improve this answer | |
  • I've tried all your settings and it still doesn't work unless I go in and tick the "Make the index template in this group your site's home page?" in the Template manager 'Edit Group'. Or I include the template group name in the url: domain.co.uk/template_group/item/url_title – Paul Frost Jan 6 '13 at 21:57
  • PATH_INFO didn't work, I had to change it back to AUTO. I'm on a standard cPanel server setup. – Paul Frost Jan 6 '13 at 22:03
  • You have the ISP pointing the subdomain/subsite domain to the correct folder? Does the subsite load if you use the subdomain with the /index.php? If so, it maybe your .htaccess file. Try renaming it, so it doesn't load to see if you can get it to work. Those are the basic components for setting up a non-MSM subsite, we've got over 20 subsites for 3 different clients running this way. – nonprofit_tech Jan 6 '13 at 22:16
  • Yes it all works perfectly with and without the .htaccess, it's just that it needs the template_group in the url if it's not the default_template_group. I'm off to bed now and will look again tomorrow. – Paul Frost Jan 6 '13 at 22:33
  • That's not working perfectly. Tell me this, when just using the subdomain, say subdomain.org does it display the primary domain? If so, it's possible your domain is not properly pointed. Try calling just a basic .htm file. Something from within the subdomain, so like subdomain.org/index.htm You can just put 'hello world' text in it. The index.htm file needs to be placed in the subdomain folder. Get some sleep and then, Let me know what happens. – nonprofit_tech Jan 6 '13 at 22:50
1

This answer is correct if you have an open_basedir restriction on your server setup and you can't set the template_group as the default one. But there is another solution that may work for you and that is in my next answer.

I've now done loads of tests and have come to the conclusion it's not possible to leave out the template_group from the url unless it is using the default template group.

Each template_group has the following templates: index _home _category _single-entry 404

For info the simplified index template code I'm using is:

{if segment_1 == "category" AND segment_2 !=""}{embed="subsite/_category"}
{if:elseif segment_1 !=""}{embed="subsite/_single-entry"}
{if:else}{embed="subsite/_home"}
{/if}

The .htaccess cose is bog standard:

#remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]
# remove index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

As soon as you add a segment to the url it looks for a matching template in the default template group. So if you set the template group and template in the subsite index.php like:

$assign_to_config['template_group'] = 'subsite';
$assign_to_config['template'] = 'index';

Then visit subsite.org It will load the index template from the subsite template group, but as soon as you add a segment it looks in the default template group for a template name matching the segment and then loads the main sites template, if there is no template name matching the segment it will load the default template group index template (whilst still displaying the subsite url in the address bar).

I tried adding a template to the default template group (subsite-index) and then changed the index.php to:

$assign_to_config['template_group'] = 'mainsite';
$assign_to_config['template'] = 'subsite-index';

Again, it loads the subsite-index template when the url has no segments but as soon as you add one it loads the mainsites templates.

The correct domain name is always showing in the browser address bar and plain html files can be called/viewed from either domain.

Studying the James Smith URL schematic closer it does seem to confirm my findings. There is no global variable for default_template_group and the database entry in 'exp_template_groups' has a field 'is_site_default' y or n. Then in numerous system folder files a check is done to establish the template_group, an example from core.template.php is below:

// We we are not enforcing strict URLs, so Let's fetch the the name of the default template group
$result = $DB->query("SELECT group_name, group_id FROM exp_template_groups WHERE a is_site_default = 'y' AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
// No result?  Bail out...
// There's really nothing else to do here. We don't have a valid template group in the URL
// and the admin doesn't have a template group defined as the site default.
| improve this answer | |
  • That's not true. These sites: privacy-information.org, madisonnonprofitday.org, consumerservicesguide.org, and wirelessed.org are all sub-sites without using MSM. The template_group is provided via the index.php file. What it does mean, is that if you want to use templates outside of the defined template_group, you need to add the index.php back into the mix. Though it can be harder on some servers versus others. – nonprofit_tech Jan 8 '13 at 0:46
  • Just thought, also try commenting out the remove trailing slash info in your .htaccess file. Sometimes the .htacess file can cause issues. Sometimes its good to test only against the component you need, which is the remove index.php component, not the trailing slash component. – nonprofit_tech Jan 8 '13 at 6:39
  • I really appreciate you taking the time to help me on this. I thought I suddenly had it with your comment about templates outside of the default_template_group being a problem. So I created subsite templates in the default group like _subsite-category and _subsite-item and called them using the conditional subsite-index, all in the default template group. Still failed as it reverts to the index template on reloads. – Paul Frost Jan 8 '13 at 11:21
  • You can see from my second answer below that I think I've solved it, but if you use a different method I'd be interested to hear how. What is your template group/template structure? Are you using any clever .htaccess to redirect/rewrite? – Paul Frost Jan 8 '13 at 11:49
0

This is the answer I'm going for. It works on my server setup which has an open_basedir restriction. It allows you to have very short url's and does not require a template group as segment_1.

This was tested on EE 2.5.5, both Core and Full license versions on a shared server hosting package running cPanel.

You need to define some additional global_vars as suggested by @nonprofit_tech. You need to do this for the index.php file for every subsite.

/* CUSTOM CONFIG VALUES */
$assign_to_config['template_group'] = 'name of default template group';
$assign_to_config['template'] = 'index';
$assign_to_config['site_index'] = '';
$assign_to_config['site_404'] = 'name of subsite template group/404';
$assign_to_config['cp_url'] = '';
$assign_to_config['global_vars'] = array(
'subsite_id' => 'subsite',
'domain' => 'http://www.subsite.org',
'site_name' => 'Subsite',
); 

Then in the index template of the default template group I used this code to conditionally embed the correct template group and template using the {subsite_id}:

{if segment_1 == "category" AND segment_2 !=""}{embed="{subsite_id}/_category"}
{if:elseif segment_1 !=""}{embed="{subsite_id}/_single-entry"}
{if:else}{embed="{subsite_id}/_home"}
{/if}

Then you just create new template groups with the same name as the {subsite_id} variable. I guess you don't have to use embeds, but whatever method you use, stash, snippets etc. use the {subsite_id} to customise the call.

| improve this answer | |
  • Every web server is different, so if this works, it works. I forgot to mention the importance of template_group matching subsite_id. It's such a habit. Templates in the group: index, article, and archive. Then anything that would have been a new section for the subsite becomes a template (like say 'about'), which uses {segments} to swap content in and out. So we can still have urls like: subsite.org/about/who-we-are or subsite.org/books/review/out-of-our-minds. We also use subsite_id to filter data so users can assign entries to subsites via a multi-select field. – nonprofit_tech Jan 8 '13 at 12:28
  • If this is the final answer for you, then you should select your own response as the solution, so the issue is listed as solved. You can always add comments or vote up other items as you see fit. – nonprofit_tech Jan 8 '13 at 12:30
  • Are you doing the same as I suggest in having the index template in the default template group as being the master index and using the {subsite_id} to conditionally load the matching subsite templates? Otherwise I can't see how you are managing it, as it's EE that is setting the rules about which index template to load, not the server. – Paul Frost Jan 8 '13 at 12:51
  • No, our index page for the subsite is the subsite/index page. The only issues we've had with this process is after upgrading to EE2, we had to switch to PATH_INFO for URI handling. Before that, with EE1, we changed our default .htaccess file. I can't remember what we removed. I do recall we had 3 .htaccess rule groupings that modified EE, but we reduced it to just the remove index.php (of course other security measures are still there, aliases, and redirects). I recall, some people not being able to use old method and it was server specific. I think that was partially why MSM was introduced. – nonprofit_tech Jan 8 '13 at 13:35
  • I'm holding back on saying if I have a solution as I don't think I really have. I've now come to the conclusion that any conditional in the index template is not evaluated if it is not in the default template group. This may be a bug in 2.5.5, which I'm using. – Paul Frost Jan 8 '13 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.