3

Is it possible to run a subsection of a site, a blog for instance, from a subdomain (i.e. blog.mysite.com) and manage it from the same EE Control Panel without the use of MSM?

1
  • This site helped a bit but since my config file resides above root, a modification borrowed from Erik Reagan's Master Config file, the site threw up PHP errors. I went back to the approach below from @blenddev and I was able to at least get to a database error with the following line SELECT * FROM ('exp_sites') WHERE 'site_id' = 1. – Stuart McCoy Dec 5 '12 at 21:01
6

Yes. Copy the index.php from the main site and update the system path variable, and the following

$assign_to_config['template_group'] = 'your-template-group';
$assign_to_config['template'] = 'your-template';
$assign_to_config['site_index'] = 'http://blog.yoursite.com/';
5
  • Tried this approach and I get a database error. Here's what I did, I added a new blog.test.dev to my vhosts/hosts files and restarted apache (local test site for now). I created a folder called blog and placed it at the same level as my test.dev system folder which is above root. I copied the index.php file from my root folder and placed it in /blog and made the changes noted above. My system folder is hardcoded for now so it's /users/[username]/sites/sandbox/test_site/system. What have I missed? – Stuart McCoy Dec 5 '12 at 15:30
  • I should have added that I turned debug on so that's how I discovered the database error. – Stuart McCoy Dec 5 '12 at 15:38
  • Hi Stuart, what is the database error you are getting? – Mel Dec 11 '12 at 14:45
  • Not in front of the computer right now but I believe it was a 1046 error and was related to the site_id. – Stuart McCoy Dec 11 '12 at 17:09
  • Just to conform, the exact error is this: A Database Error Occurred Error Number: 1046 No database selected SELECT * FROM ('exp_sites') WHERE 'site_id' = 1 Filename: core/EE_Config.php Line Number: 211 – Stuart McCoy Dec 12 '12 at 14:16
5

Another option is having a faux subdomain mapped to a template group in the existing site via .htaccess.

For example:

RewriteCond %{HTTP_HOST} ^blog.mysite.com [NC]
#whatever exclusions you need for index rewrite:
RewriteCond $1 !^(images|themes|assets|media\/|index\.php|([a-z0-9-]+).html) [NC] 
RewriteRule ^(.*)$ /index.php/blog/$1 [L]

This would need to go before the main site's index.php rewrite in the .htaccess.

Going to blog.mysite.com/category-1 would really be accessing www.mysite.com/blog/category-1

It's likely not the most elegant solution, but I've seen it work well for a mobile site.

1
  • I've done this on sites as well. For extra #eecms geek cred, this was done on a site managed in MSM but where we didn't want to waste more sites. ;-) – Ian Pitts Dec 4 '12 at 16:51
4

Another option is to serve all the domains out of the same set of files. This will point the primary and subdomain at the same file set. Then all you have to do is just check the $_SERVER['SERVER_NAME'] and set the config variables based on the different subdomains.

Its how I setup a mobile site in EE. Only one set of files, but I just changed a few vars (including template path) and was able to serve up a totally different template set, but using the exact same content, based on the server name.

if($_SERVER['SERVER_NAME'] == 'm.example.com'){
    $assign_to_config['template_group'] = '';
    $assign_to_config['template'] = '';
    $assign_to_config['site_index'] = '';
    $assign_to_config['site_url'] = 'http://m.example.com/';
    $assign_to_config['site_404'] = '';
}
6
  • Interesting. So, what would the settings look like for a typical site in your example? Could you have more than one template group/templates? Do you even need to assign a template and 404 to the subdomain? – Stuart McCoy Nov 28 '12 at 2:28
  • No you don't need to assign all those variables(I was just including that to show how you could set different variables based on the subdomain). If you want you could just set a default set of settings for all the subdomains, then change just the one or two (or none) you need to change for the different subdomains. You can have multiple template groups/templates b/c you can set a different location for the template file path in e config file. – blenddev Nov 28 '12 at 2:58
  • I'm working locally for the time being which might be part of the problem but here's what I did. I added blog.test.dev to my vhosts.conf and hosts files so I had a subdomain to work with. I created a template group and basic template to test the subdomain. I then added your code to the config file for test.dev and changed the SERVER_NAME, template_group, template, and site_url variables. I removed the rest as I don't think I need them for this test. That's it, and all I get right now when I go to blog.test.dev is a blank white page. When I go to test.dev/blog the template works. Thoughts? – Stuart McCoy Dec 3 '12 at 13:58
  • Do you have the blog/index template set as the default template for blog.test.dev? going to blog.test.dev is going to take you to the home page of the install. (default_group/index). Is the current home template blank or is that not what is being returned when you go to blog.test.dev? – blenddev Dec 3 '12 at 17:33
  • I did set template_group and template to 'blog' and 'index'. The current home page template is not blank either. Simple structure site used to test a few things. I think I might be a little confused here though. How can I set my blog/index as the default template without setting up another EE site for blog.ee.dev? – Stuart McCoy Dec 5 '12 at 15:16
3

The old method of running multiple sites still works as of the latest EE 2 release. To use that, you need an index.php for each site and you'd use the assign_to_config values for anything site-specific. For example, I have this setup for one of my subsites (it runs in a subfolder rather than a subdomain, but principle should be the same I believe):

$assign_to_config['template_group'] = '';
$assign_to_config['template'] = '';
$assign_to_config['site_index'] = '';
$assign_to_config['site_url'] = 'http://www.westeros.org/BoD/';
$assign_to_config['site_404'] = '';
$assign_to_config['global_vars'] = array('site' => 'BoD');

I basically just set a default site url to get the right base url for that site and then I define a site variable so that I can have two or more sites sharing my "News" template group, for example.

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.