3

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.

  • A simple redirect is not what you're after, I assume? So a user loading b.com doesn't know that the same content is also available on a.com/sub? – carlcs Apr 13 '15 at 13:09
  • Exactly. The domain should be clean. In the end what im after is like having a another "single" acting as a homepage but triggered by specific domains only. – nexflo Apr 13 '15 at 13:11
5

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(
    '*' => array(
        // ...
    ),
    'a.com' => array(
        // ...
        'domain' => 'a',
    ),
    'b.com' => array(
        // ...
        'domain' => '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 }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.