Answers.Body: <p>So I was making this more complicated than necessary, there was no need to go near the .htaccess. In the end I used something similar to Mats' answer and used a dynamic include. Each site has templates in a sub-folder and the prefix for this is set in the general.php config settings based on the URL. It's then used in the following include statement in the relevant template.</p>
  
  <pre><code>{% include '_' ~ craft.config.sitePrefix ~ '/path/to/template' %}
  </code></pre>
  
  <p>With regard to my poor explanation, by 'path segments'I actually meant the 'Entry URL Format' which must be unique for singles which was where I was confused. For the blog channels for each site I could set it to <code>blog/{slug}</code> and let Craft sort it out displaying the correct template set in the settings. Any duplication in singles' URLs was overcome with a generic include template that switched based on the config setting.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-02T09:54:40.857Z
Answers.LastActivityDate: 2016-02-02T09:54:40.857Z
Answers.UserDisplayName: Neal Hulme
Answers.Body: <p>In Craft, there is no such thing as a "section path" – there's only the "Entry Template" path (which tells Craft which template to load when the URL for an Entry in that particular section is requested) and the "URL format", which tells Craft how it should construct the URLs for the entries within that section. </p>
  
  <p>It's actually totally possible to have multiple sections use the same URL format – e.g. <code>blog/{slug}</code> – so that part is easy; <em>just use the same format for both of your blog sections</em>, and all your URLs will be consistent out of the box (the only drawback to be aware of is that if you create entries with identical names within both sections, Craft will suffix the auto-generated slug for the newer entry with a number, i.e. <code>my-generic-blog-post-title-2</code>).</p>
  
  <p>I'm assuming your blogs should use different templates for both their index and entry pages, so with the above URL format in place, it's simply a matter of routing the requests to the correct template(s).</p>
  
  <p>The entry template is easy. You can set different paths for the two blog section's Entry Template path settings, e.g. <code>blog/blogA/_entry</code> and <code>blog/blogB/_entry</code>, or you can use the same path, e.g. <code>blog/_entry</code> for both. If you use the same template, you can conditionally <code>{% include %}</code> a blog specific template by testing the <code>entry.section.handle</code> value, e.g.</p>
  
  <pre><code>{% switch entry.section.handle %}
      {% case 'blogA' %}
          {% include 'blog/blogA/_entry' %}
      {% case 'blogB' %}
          {% include 'blog/blogB/_entry' %}
  {% endswitch %}
  </code></pre>
  
  <p>For the blog indexes – i.e. <code>domain.com/blog</code> and <code>domain-two.com/blog</code> – it's important to realize that in Craft, <em>there is no inherent relationship between templates and sections</em>. For instance, even if you have a section with the handle <code>blog</code> and a template <code>templates/blog/index</code>, Craft won't automatically "connect" the template and the section, in terms of, for instance, populating the template with entries or other data related to the <code>blog</code> section.</p>
  
  <p>What Craft <em>will</em> do, is to route all templates (that aren't hidden using an underscore prefix, i.e. <code>_secret.html</code>) to URLs. This means that if you <em>do</em> have a template under <code>templates/blog/index.html</code> or <code>templates/blog.html</code>, Craft will load that template whenever the URL <code>domain.com/blog</code> (and <code>domain-two.com/blog</code>) is requested.</p>
  
  <p>In your case, you can exploit this behaviour by creating a template called <code>templates/blog/index.html</code>. Inside that template, you can add a <code>{% switch %}</code> statement similar to the one in the entry template, but this time looking at the <code>craft.request.serverName</code> variable (I'm assuming you've created index templates for each of your blog sections under <code>templates/blog/(sectionHandle)/index.html</code>):</p>
  
  <pre><code>{% switch craft.request.servername %}
     {% case 'domain.com' %}
         {% include 'blog/blogA/index' %}
     {% case 'domain-two.com' %}
         {% include 'blog/blogB/index' %}
  {% endswitch %}
  </code></pre>
  
  <p>If you're looking for a more robust solution, you should look at <a href="https://craftcms.com/docs/multi-environment-configs" rel="nofollow">Craft's multi-environment features</a>, or possibly make use of the <a href="https://craftcms.com/docs/config-settings#appId" rel="nofollow"><code>appId</code></a> config setting; i.e. use different <code>appId</code> values for the two domains, and load templates conditionally based on <code>craft.config.appId</code> instead of hard coding the hostnames in your templates. To have Craft set a different <code>appId</code> based on the different domain names, you could add something like this to your <code>craft/config/general.php</code> file:</p>
  
  <pre><code>return array(
      'domain.com' =&gt; array(
          'appId' =&gt; 'siteA', 
      ),
      'domain-two.com' =&gt; array(
          'appId' =&gt; 'siteB',
      ),
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-25T11:40:50.127Z
Answers.LastActivityDate: 2016-01-25T11:40:50.127Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have a Craft installation with two domains pointing at it. The first domain is all working and has a number of sections including a blog located at /blog. What I want to be able to do is have a different blog section for the second domain that is also at the path /blog so naming conventions are all consistent i.e.</p>
  
  <p>domain.com/blog<br>
  domain-two.com/blog</p>
  
  <p>Of course in the CP when you add another section it will not let you use the same path which makes sense. As there is a lot of shared information but also a couple of sections/pages that will be different I thought perhaps using the .htaccess to rewrite the URL to include an additional path segment for the second site which could then be used in the CP to distinguish unique paths.</p>
  
  <p>I tried modifying the .htaccess RewriteRule but could not get this to reflect in the information passed through to Craft.</p>
  
  <p><code>RewriteCond %{HTTP_HOST} ^domain-two.com$</code><br>
  <code>RewriteRule (.+) domain-two/index.php?p=$1 [QSA,L]</code></p>
  
  <p>or</p>
  
  <p><code>RewriteCond %{HTTP_HOST} ^domain-two.com$</code><br>
  <code>RewriteRule (.+) index.php?p=domain-two/$1 [QSA,L]</code></p>
  
  <p>Is there a way to make the rewrite work, I'm probably doing something wrong, or is there a better way to trigger a unique path from the same URL path? I really need to keep the URLs consistent.</p>
  
Tags: <htaccess><multi-domain>
Title: Re-using path segments for an additional domain?
ThreadText: # Re-using path segments for an additional domain?
  
  (Asked by: username_0 on 2016-01-25)
  
  I have a Craft installation with two domains pointing at it. The first domain is all working and has a number of sections including a blog located at /blog. What I want to be able to do is have a different blog section for the second domain that is also at the path /blog so naming conventions are all consistent i.e.
  
  domain.com/blog  
  domain-two.com/blog
  
  Of course in the CP when you add another section it will not let you use the same path which makes sense. As there is a lot of shared information but also a couple of sections/pages that will be different I thought perhaps using the .htaccess to rewrite the URL to include an additional path segment for the second site which could then be used in the CP to distinguish unique paths.
  
  I tried modifying the .htaccess RewriteRule but could not get this to reflect in the information passed through to Craft.
  
  `RewriteCond %{HTTP_HOST} ^domain-two.com$`  
  `RewriteRule (.+) domain-two/index.php?p=$1 [QSA,L]`
  
  or
  
  `RewriteCond %{HTTP_HOST} ^domain-two.com$`  
  `RewriteRule (.+) index.php?p=domain-two/$1 [QSA,L]`
  
  Is there a way to make the rewrite work, I'm probably doing something wrong, or is there a better way to trigger a unique path from the same URL path? I really need to keep the URLs consistent.
  
  **Tags:** htaccess, multi-domain
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-02-02. Score: 0 | Accepted answer
  
  So I was making this more complicated than necessary, there was no need to go near the .htaccess. In the end I used something similar to username_1' answer and used a dynamic include. Each site has templates in a sub-folder and the prefix for this is set in the general.php config settings based on the URL. It's then used in the following include statement in the relevant template.
  
  ```
  {% include '_' ~ craft.config.sitePrefix ~ '/path/to/template' %}
  
  ```
  
  With regard to my poor explanation, by 'path segments'I actually meant the 'Entry URL Format' which must be unique for singles which was where I was confused. For the blog channels for each site I could set it to `blog/{slug}` and let Craft sort it out displaying the correct template set in the settings. Any duplication in singles' URLs was overcome with a generic include template that switched based on the config setting.
  
  
  ---
  
  ### Answer by username_1 on 2016-01-25. Score: 2
  
  In Craft, there is no such thing as a "section path" – there's only the "Entry Template" path (which tells Craft which template to load when the URL for an Entry in that particular section is requested) and the "URL format", which tells Craft how it should construct the URLs for the entries within that section.
  
  It's actually totally possible to have multiple sections use the same URL format – e.g. `blog/{slug}` – so that part is easy; *just use the same format for both of your blog sections*, and all your URLs will be consistent out of the box (the only drawback to be aware of is that if you create entries with identical names within both sections, Craft will suffix the auto-generated slug for the newer entry with a number, i.e. `my-generic-blog-post-title-2`).
  
  I'm assuming your blogs should use different templates for both their index and entry pages, so with the above URL format in place, it's simply a matter of routing the requests to the correct template(s).
  
  The entry template is easy. You can set different paths for the two blog section's Entry Template path settings, e.g. `blog/blogA/_entry` and `blog/blogB/_entry`, or you can use the same path, e.g. `blog/_entry` for both. If you use the same template, you can conditionally `{% include %}` a blog specific template by testing the `entry.section.handle` value, e.g.
  
  ```
  {% switch entry.section.handle %}
      {% case 'blogA' %}
          {% include 'blog/blogA/_entry' %}
      {% case 'blogB' %}
          {% include 'blog/blogB/_entry' %}
  {% endswitch %}
  
  ```
  
  For the blog indexes – i.e. `domain.com/blog` and `domain-two.com/blog` – it's important to realize that in Craft, *there is no inherent relationship between templates and sections*. For instance, even if you have a section with the handle `blog` and a template `templates/blog/index`, Craft won't automatically "connect" the template and the section, in terms of, for instance, populating the template with entries or other data related to the `blog` section.
  
  What Craft *will* do, is to route all templates (that aren't hidden using an underscore prefix, i.e. `_secret.html`) to URLs. This means that if you *do* have a template under `templates/blog/index.html` or `templates/blog.html`, Craft will load that template whenever the URL `domain.com/blog` (and `domain-two.com/blog`) is requested.
  
  In your case, you can exploit this behaviour by creating a template called `templates/blog/index.html`. Inside that template, you can add a `{% switch %}` statement similar to the one in the entry template, but this time looking at the `craft.request.serverName` variable (I'm assuming you've created index templates for each of your blog sections under `templates/blog/(sectionHandle)/index.html`):
  
  ```
  {% switch craft.request.servername %}
     {% case 'domain.com' %}
         {% include 'blog/blogA/index' %}
     {% case 'domain-two.com' %}
         {% include 'blog/blogB/index' %}
  {% endswitch %}
  
  ```
  
  If you're looking for a more robust solution, you should look at [Craft's multi-environment features](https://craftcms.com/docs/multi-environment-configs), or possibly make use of the [`appId`](https://craftcms.com/docs/config-settings#appId) config setting; i.e. use different `appId` values for the two domains, and load templates conditionally based on `craft.config.appId` instead of hard coding the hostnames in your templates. To have Craft set a different `appId` based on the different domain names, you could add something like this to your `craft/config/general.php` file:
  
  ```
  return array(
      'domain.com' => array(
          'appId' => 'siteA', 
      ),
      'domain-two.com' => array(
          'appId' => 'siteB',
      ),
  );
  
  ```
  
  
  ---
  
  