ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Multiple domain/subdomain idea (entirely within EE)

August 27, 2010 8:24am

Subscribe [3]
  • #1 / Aug 27, 2010 8:24am

    Mitch Cohen

    12 posts

    I’m working on an EE site for a college.  They want multiple subdomains - say http://www.college.edu, math.college.edu, compsci.college.edu - each to bring up unique pages.  Much of the content is shared between them; it’s more of how the user sees the site’s introduction.  Site management is also shared between the subdomains.

    I’ve seen a few ways to make this happen in the wiki and elsewhere.  I wanted to do this entirely inside EE, without using multiple root index.php files or editing the root index.php file.  This is what I’ve done; I’m looking for feedback from those with more EE experience to point out potential problems with this or even to say it’s ok.

    First, I added the subdomains to the server configuration, pointing to the same server path as www (basically a domain alias).  So for the moment www, math, and compsci bring up the exact same home page.

    Then I created a template group for each subdomain - www, math, compsci, etc, and built the index template for each group to appear as I’d like.

    Then I created a template group called “subdomain_chooser” and made its index template the site’s home page.

    I gave subdomain_chooser/index the right to run PHP on input, and used this as the template’s contents:

    <?php
          if ($_SERVER['HTTP_HOST'] == "math.college.edu")
          {
                echo '{embed="math/index"}';
          }
          elseif ($_SERVER['HTTP_HOST'] == "compsci.college.edu")
          {
                echo '{embed="compsci/index"}';
          }
          else
          {
                echo '{embed="www/index"}';
          }
    ?>

    At least in simple testing (the site is still being built) everything works as expected.

    There are some understood caveats which I am not concerned about:

    -These are not multiple sites by my understanding, so the MSM isn’t needed here.  Just unique entry points into the same set of content.  And there will be a ton of subdomains.
    -Security implications of running PHP inside a template.  I’ll need to do this elsewhere too, for other reasons.
    -Understanding that a handcrafted URL of http://www.college.edu/math/ would bring up the math “home” page.  No problem.
    -SEO or other implications of using multiple subdomains versus one large www.  This decision was for marketing purposes and needs to happen.

    Any thoughts on the above method to solve this problem?

    Thanks,

      Mitch

  • #2 / Aug 27, 2010 8:58am

    Ingmar

    29245 posts

    Just for the record, yes, the supported way of running multiple sites would be using the Multi Site Manager. Apart from that, this or similar approaches are perfectly fine and doable.

    Running PHP inside templates poses no risk as such. Just be aware that people with editing access to such templates that are not also Superadmins could use PHP to elevate their account to this status for all practical purposes.  Being able to run PHP + access to the database = the world is your oyster.

  • #3 / Aug 29, 2010 11:01pm

    Mitch Cohen

    12 posts

    Hi,

    Thanks - just what I was hoping to hear.

    (Re: the PHP/Template risk - yes, it’s all about who can edit the template.  If all goes well, they’ll be fully locked down.)

    Thanks again,

      Mitch

  • #4 / Sep 27, 2010 1:52pm

    vorari

    40 posts

    I attempted this - was not able to get it to work.. has this functionality been deprecated in any way in EE2.1?

    Thanks,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases