<p>To do this, copy index.php and .htaccess from a.com’s webroot into b.com’s, and make sure the <code>$craftPath</code> variable is correct.</p>

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

<pre class="lang-php prettyprint-override"><code>$craftPath = '../craft';

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

// ...
</code></pre>

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

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



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

<p>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 <code>domain</code> config setting that varies depending on the requested domain:</p>

<pre class="lang-php prettyprint-override"><code>return array(
    '*' =&gt; array(
        // ...
    ),
    'a.com' =&gt; array(
        // ...
        'domain' =&gt; 'a',
    ),
    'b.com' =&gt; array(
        // ...
        'domain' =&gt; 'b',
    ),
);
</code></pre>

<p>Then in your templates, only run that <code>str_replace</code> filter when the domain is <code>b</code>:</p>



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

CC BY-SA 3.0
2015-06-19T21:46:35.660Z
Thanks for this - invaluable. But I only seem able to get this to work by prepending the `subpath/` to `$_SERVER['REQUEST_URI']`, rather than `$_GET['p']`: http://craftcms.stackexchange.com/a/10246/3686
Phil Gyford
CC BY-SA 3.0
2015-04-13T13:19:15.870Z
2015-04-13T13:33:57.760Z
2015-04-13T13:33:57.760Z
Brandon Kelly
<p>We are launching 2 different sites, using the same craft installation on multiple domains.</p>

<p>a.com and b.com</p>

<p>a.com points to the main craft install</p>

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

<p>What is the best craft internal way of doing this?</p>

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

<p>Thanks in advance.</p>

CC BY-SA 3.0
2015-04-13T13:09:35.213Z
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
CC BY-SA 3.0
2015-04-13T13:11:15.157Z
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
<routing><multi-domain>
Multi-Domain routing
# Multi-Domain routing

(Asked by: username_0 on 2015-04-13)

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.

**Tags:** routing, multi-domain

> **Comments:**
> **username_1**: 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?  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_2 on 2015-04-13. Score: 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 }}

> **Comments:**
> **username_3**: Thanks for this - invaluable. But I only seem able to get this to work by prepending the `subpath/` to `$_SERVER['REQUEST_URI']`, rather than `$_GET['p']`: http://craftcms.stackexchange.com/a/10246/3686  

---

