Elgg and domain aliases

During setup we have to fill in the website url. This is used to prefix all internal links.

But what if i have multiple domains that point to the same social network and i want to keep the domain in the addressbar?

For example: www.maindomain.com, www.aliasdomain.com, alias.domain.com

When i go to www.aliasdomain.com or alias.domain.com I still get to see www.maindomain.com, but would like to see www.aliasdomain.com or alias.domain.com in the address bar.

Any ideas?

  • Options:

    1. Setup a proxy server

    2. You could try changing the config value for the site URL on the fly. It is loaded from the database, but you could detect it instead.

  • Changing $CONFIG->wwwroot on the fly, for example in my theme plugin? That seems do-able.

    Tx Cash 

  • For reasons that I do not understand, the site URL is stored in both $CONFIG->wwwroot and $CONFIG->url. Also make sure that this is done in a function that runs very early in the boot process.

  • ... there are even 3 of those and at least in 1.8 $CONFIG->www_root is populated with the URL from the session object whereas $CONFIG->wwwroot is populated from the URL stored with the site ... :-) which might be different in your case ...

  • I'll experiment with the given suggestions, although i think the 3 $CONFIG values should be streamlined. 

  • Ok, i ended up with the following code, but it feels a bit hacky and not elggy.

    in my start.php i first do a call to the function that does the magic, just before the theme_init call. i first did the check_view inside the theme_init, but that doesn't work.

    my question is now: is there any point in the event system that my check_view should be in? 

     

    start.php:

    check_view();
    elgg_register_event_handler('init', 'system', 'theme_init'); 

    function check_view() {
      global $CONFIG;

      $domainpart = $_SERVER['HTTP_HOST'];
      $CONFIG->wwwroot = "http://" . $domainpart ."/";  
      $parsedUrl = parse_url($CONFIG->wwwroot);
      $host = explode('.', $parsedUrl['host']);  

      $subdomain = $host[0];

      if (in_array($subdomain, array('iframe','mobile','m'))) {
        elgg_set_viewtype($subdomain);
        elgg_register_viewtype_fallback('default')    
      }
    }

    ...