TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Multi-domain application
  • Hi all,

    Trying to see if I can get some thoughts on how to best achieve this without reinventing the wheel. Ideally, this is NOT another CMS-ish effort but it will sound like it. Here is what I am trying to get done:

    Both these should go to the same kohana application and pull up the same page and the URLs should be able to co-exist at the same time. The non-custom domain one is easy as that just goes to a controller and action and pulls up the proper page content depending on the <name>. Now the trickier part is supporting the Custom domain

    • Set up DNS for custom domain
      • Simple way:
        • Go to registrar, point @ and www to IP address of example.com
      • Complex (load balanced):
        • Go to registrar and point nameservers to Amazon R53
        • Use Amazon R53 to add at least 3 IPs of example.com to DNS for @ and www
    • Nginx for custom domain
      • Create new sites-available/sites-enabled entry
        • Create server section to point to kohana document root (where index.php is located)
        • /var/www/kohana/web (this is the folder where index.php, application, system, modules, etc. lives)

    After you get here, you basically get something like

    I think I need some sort of rewrite rule inside the nginx sites-available config to do the rewrite properly so that the following are true:

    • http://bob.com/about => WORKS
    • http://bob.com/sue/about => this should NOT work
    • http://example.com/bob/about => WORKS
    • http://example.com/sue/about => WORKS

    Any ideas on this last piece of rewrite or is there is a better way of achieving this?

    Thanks, Chris

  • I'm assuming you have some sort of config file or database that defines what domains are valid and what names they map to, being that (at least in your example) the domains don't match exactly to the names.. e.g. what if you have "bob.com" and "bob.net", do they both match the "bob" name?

    In your bootstrap you're going to need to do some checking of the domain, and then adjust your routes accordingly. Let's assume you have a "Domain" class that checks whether the domain is valid, and returns the appropriate name for the domain (this could be from a config file or a database):

    $domain = new Domain($_SERVER["SERVER_NAME"]);
    $name = $domain->name(); // this should return FALSE for "example.com"
    if ( ! $name)
        Route::set('default', '<name>(/<controller>(/<id>))')
                'controller'    => 'home',
                'action'        => 'index',
        Route::set('default', '(<controller>(/<id>))')
                'name'          => $name,
                'controller'    => 'home',
                'action'        => 'index',
  • Hi talisto, this could work - thanks for the idea

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion