Multi-Domain routing We are launching 2 different sites, using the same craft installation on multiple domains.

a.com and b.com

a.com points to the main craft install

b.com should point to a subpage/single in this same craft install.
(So basically could be reached via a.com/subpage

What is the best craft internal way of doing this?

I know there is mod proxy..but we wanna handle it internally. So basically different "start" points for different domains or subdomains.

Thanks in advance.
To do this, copy index.php and .htaccess from a.com’s webroot into b.com’s, and make sure the $craftPath variable is correct.

Then, around where $craftPath is getting defined, override $_GET['p'] to make Craft think that the URI actually started with subpath:

$craftPath = '../craft';

$_GET['p'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');

// ...


Now when you go to b.com/*, it will be the same as going to a.com/subpath/*.

If you want traffic going to b.com to stay on b.com, you will also need to make sure a.com/subpath is replaced with b.com in any Craft-generated URLs:



{{ url('foo')|replace('a.com/subpath', 'b.com') }}


That will also affect links on a.com, though. If you still want traffic on a.com/subpath to remain on a.com, then it’s slightly more complicated. In your craft/config/general.php file, add a custom domain config setting that varies depending on the requested domain:

return array(
    '*' =&gt; array(
        // ...
    ),
    'a.com' =&gt; array(
        // ...
        'domain' =&gt; 'a',
    ),
    'b.com' =&gt; array(
        // ...
        'domain' =&gt; 'b',
    ),
);


Then in your templates, only run that str_replace filter when the domain is b:



{% set url = url('foo') %}
{{ craft.config.domain == 'b' ? url|replace('a.com/subpath', 'b.com') : url }}