Answers.Body: <p>I've found an answer, but I don't know if it's going to cause me any problems or not. Looking at the debug output in the JS Console I noticed that although<br>
  <code>$_GET['p']</code> was set correctly to <code>subpath/directory</code>,<br>
  <code>$_SERVER['REQUEST_URI']</code> was only set to <code>/directory</code> and<br>
  <code>$_SERVER['QUERY_STRING']</code> was only set to <code>p=directory</code>. Maybe Craft or Yii uses the <code>REQUEST_URI</code> rather than <code>$_GET['p']</code> at some crucial stage?</p>
  
  <p>So I've replaced the <code>$_GET['p']...</code> line in my <code>b.com/index.php</code> with this:</p>
  
  <pre><code>$_SERVER['REQUEST_URI'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  </code></pre>
  
  <p>That seems to fix things. Any reason this might be bad and wrong?</p>
  
  <p><strong>UPDATE:</strong> Looking back at my code now, it seems that both lines were required, to cover all occasions. So I now have this in <code>b.com/index.php</code>:</p>
  
  <pre><code>$_SERVER['REQUEST_URI'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  
  $_GET['p'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-05T10:16:57.370Z
Answers.Text: Hi this is exactly what I need to do for a site I am building. Did you experience any problems doing it this way or did it work out Ok for you? Cheers
Answers.UserDisplayName: Lettie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T11:29:57.117Z
Answers.Text: I just looked back at my code and it looks like it still works - I've updated my answer with the latest version.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-19T20:25:53.863Z
Answers.LastActivityDate: 2016-03-07T11:29:12.837Z
Answers.LastEditDate: 2016-03-07T11:29:12.837Z
Answers.UserDisplayName: Phil Gyford
Body: <p>I've followed <a href="https://craftcms.stackexchange.com/a/9170/3686">this answer</a> for running a Craft install based on two domain names. I thought it was working but either I was wrong, or something's changed, because it's not now.</p>
  
  <p>I have a.com (where the Craft install is) and b.com. In b.com's <code>index.php</code> I have this:</p>
  
  <pre><code>$craftPath = '../craft';
  
  $_GET['p'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  </code></pre>
  
  <p>So that if I go to <code>b.com/directory</code> it loads a page as if it was <code>a.com/subpath/directory</code>.</p>
  
  <p>Except it's not - it's as if it's trying to load <code>a.com/directory</code>.</p>
  
  <p>If I put this in b.com's <code>index.php</code> (after the above):</p>
  
  <pre><code>var_dump($_GET['p']);
  exit();
  </code></pre>
  
  <p>Then I see "subpath/directory", as expected. But if in my base layout template I put this:</p>
  
  <pre><code>{{ craft.request.getQueryString() }}
  </code></pre>
  
  <p>Then it shows "p=directory". So it seems like "subpath/" is going missing somewhere? I'm stumped.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If I request <code>b.com/index.php?p=directory</code> then I get the page I expect (ie, <code>/subpath/directory</code>).</p>
  
Tags: <routing><multi-domain>
Title: Multi-domain routing not working
ThreadText: # Multi-domain routing not working
  
  (Asked by: username_0 on 2015-06-19)
  
  I've followed [this answer](https://craftcms.stackexchange.com/a/9170/3686) for running a Craft install based on two domain names. I thought it was working but either I was wrong, or something's changed, because it's not now.
  
  I have a.com (where the Craft install is) and b.com. In b.com's `index.php` I have this:
  
  ```
  $craftPath = '../craft';
  
  $_GET['p'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  
  ```
  
  So that if I go to `b.com/directory` it loads a page as if it was `a.com/subpath/directory`.
  
  Except it's not - it's as if it's trying to load `a.com/directory`.
  
  If I put this in b.com's `index.php` (after the above):
  
  ```
  var_dump($_GET['p']);
  exit();
  
  ```
  
  Then I see "subpath/directory", as expected. But if in my base layout template I put this:
  
  ```
  {{ craft.request.getQueryString() }}
  
  ```
  
  Then it shows "p=directory". So it seems like "subpath/" is going missing somewhere? I'm stumped.
  
  **UPDATE:**
  
  If I request `b.com/index.php?p=directory` then I get the page I expect (ie, `/subpath/directory`).
  
  **Tags:** routing, multi-domain
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-06-19. Score: 2
  
  I've found an answer, but I don't know if it's going to cause me any problems or not. Looking at the debug output in the JS Console I noticed that although  
  `$_GET['p']` was set correctly to `subpath/directory`,  
  `$_SERVER['REQUEST_URI']` was only set to `/directory` and  
  `$_SERVER['QUERY_STRING']` was only set to `p=directory`. Maybe Craft or Yii uses the `REQUEST_URI` rather than `$_GET['p']` at some crucial stage?
  
  So I've replaced the `$_GET['p']...` line in my `b.com/index.php` with this:
  
  ```
  $_SERVER['REQUEST_URI'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  
  ```
  
  That seems to fix things. Any reason this might be bad and wrong?
  
  **UPDATE:** Looking back at my code now, it seems that both lines were required, to cover all occasions. So I now have this in `b.com/index.php`:
  
  ```
  $_SERVER['REQUEST_URI'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  
  $_GET['p'] = 'subpath/' . (isset($_GET['p']) ? $_GET['p'] : '');
  
  ```
  
  > **Comments:**
  > **username_1**: Hi this is exactly what I need to do for a site I am building. Did you experience any problems doing it this way or did it work out Ok for you? Cheers  
  > **username_0**: I just looked back at my code and it looks like it still works - I've updated my answer with the latest version.  
  
  ---
  
  