How to map domains to modules

I am rebuilding a company’s three websites and combine them into one Yii application. For SEO and historical reasons I have to keep the three original domain names - each one has a different focus (training, sales and general) and slightly different look and feel. They need to be on a single application because they share a common backend.

So say the three domain urls are www.abc.com, www.def.com and www.ghi.com. I want to match them onto three modules, say abc, def and ghi. There will also be another module called admin.

How do I do this without explicitly putting the module in the url? For example, www.abc.com/ should load module/controller/view abc/default/index. So the module should not appear in the url.

The only possible exception to this would be if www.abc.com would load say module ghi eg: www.abc.com/index.php/ghi/ctrl/view - although I would still prefer that the appropriate domain is displayed - in this case www.ghi.com/index.php/ctrl/view.

I would appreciate any input on this.

This sounds similar to something I am implementing. I have a single application, and I am using urlManager to map subdomains (as opposed to TLDs) to modules.

eg.

http://www.example.com is the parent application

http://module1.example.com would show the same as http://www.example.com/module1

http://module2.example.com would show the same as http://www.example.com/module2

This is fairly easily achieved with the urlManager rules in the config/main.php file:




return array(

  ...

  'components'=>array(

    ...

    'urlManager'=>array( 

      'urlFormat'=>'path',

      'showScriptName'=>false,

      'rules'=>array(

        'http://module1.example.com/' => 'module1/',

        'http://module1.example.com/<_c:\w+>' => 'module1/<_c>',  // this MIGHT be redundant - anyone else care to comment?

        'http://module1.example.com/<_c:\w+>/<_a:\w+>/*' => 'module1/<_c>/<_a>',  // this MIGHT also be redundant.

        'http://module2.example.com/' => 'module2/',

        'http://module2.example.com/<_c:\w+>' => 'module2/<_c>',

        'http://module2.example.com/<_c:\w+>/<_a:\w+>/*' => 'module2/<_c>/<_a>',

        ...

      ),

      ...

    ),

    ...

  ),

); 



You could TRY something similar, except in place of


'http://module1.example.com/' => 'module1/',

you could put


'http://www.abc.com/' => 'abc/', // or whatever name you gave the module for this domain

You would of course need to have each domain pointing to the application’s root directory (my host allows this through parked domains).

Whether this approach would work I am not able to tell you, but it might be worth a try. Someone with a little more experience might be able to shed some light…

Many thanks for this.

This is in place - now to test the solution on the server. I’ll keep you posted.