Answers.Body: <p>It’s definitely possible. Here’s the gist:</p>
  
  <ol>
  <li>Forget the whole subdomain idea, and start by getting everything working using a URI format like <code>/client/&lt;slug&gt;</code>.</li>
  <li>Make all subdomain traffic get routed to the same server/virtual host.</li>
  <li>Make Craft <em>think</em> that subdomain requests actually had a URI in the format of <code>/client/&lt;slug&gt;</code>, so it will route the request the way it did in step 1.</li>
  </ol>
  
  <p>How you go about the second step depends on whether you’re on Nginx or Apache.</p>
  
  <ul>
  <li><p>For <strong>Nginx</strong>, add <code>default_server</code> to the server config’s <code>listen</code> directive:</p>
  
  <pre><code>server {
      listen 80 default_server;
      // ...
  }
  </code></pre></li>
  <li><p>For <strong>Apache</strong>, create a <a href="http://httpd.apache.org/docs/2.0/vhosts/examples.html#default" rel="nofollow noreferrer"><code>_default_</code> virtual host definition</a>:</p>
  
  <pre><code>&lt;VirtualHost _default_:*&gt;
      // ...
  &lt;/VirtualHost&gt;
  </code></pre></li>
  </ul>
  
  <p>Exact details depend on your hosting environment so you may need to do some of your own googling here. You’ll likely need to restart the webserver before changes take effect, too.</p>
  
  <p>Once you have all subdomain traffic routing to the same place, add something like this to your index.php file:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $domainParts = explode('.', $_SERVER['HTTP_HOST']);
  
  if (count($domainParts) === 3)
  {
      $slug = $domainParts[0];
  
      // Fake Craft into thinking the URI was actually /clients/&lt;SLUG&gt;/uri/...
  
      // Nginx:
      $_REQUEST['REQUEST_URI'] = "/clients/$slug".($_REQUEST['REQUEST_URI'] ?? '');
  
      // Apache:
      $_GET['p'] = "clients/$slug/".($_GET['p'] ?? '');
  }
  
  // ...
  </code></pre>
  
  <p>With that in place, your <code>client.domain.tld</code> requests should start serving those client entry pages!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-24T22:49:18.037Z
Answers.Text: Looking at the date, I assume that this is for Craft 2. Should this also work for Craft 3?
  
  I have a Structure and would like the level 1 entries to be available at `level-1.example.com` and level 2, 3 etc at `level-1.example.com/level-2`, `level-1.example.com/level-2/level-3`. Also, I'm using Nitro 2 and don't know how to edit the Nginx config. Thanks! (I would prefer not to use multisite if poss.)
Answers.UserDisplayName: Andrea DeMers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-02T23:11:04.110Z
Answers.LastActivityDate: 2018-02-02T23:11:04.110Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <p>Craft 3.x and Nitro 2:</p>
  <p>In Nitro 2, I added a site alias <code>level-1.example.nitro</code> via <code>nitro alias</code> and at top of index.php I have:</p>
  <pre><code>$domainParts = explode('.', $_SERVER['HTTP_HOST']);
  $uri = $_SERVER['REQUEST_URI'];
  
  if (count($domainParts) === 3)
  {
      $slug = $domainParts[0];
      $_GET['p'] = &quot;$slug/&quot;.($_GET['p'] ?? $uri);
  }
  </code></pre>
  <p>I can visit <code>level-1.example.nitro</code> and <code>level-1.example.nitro/level-2</code>, <code>level-1.example.nitro/level-2/level-3</code> with the expected results.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-25T16:13:08.810Z
Answers.LastActivityDate: 2021-02-25T16:13:08.810Z
Answers.UserDisplayName: Andrea DeMers
Body: <p>I want to assign a wildcard domain to every entry from a specific type. For instance:</p>
  
  <p><code>client.example.com</code></p>
  
  <p>Where <code>client</code> is the slug of an entry. Is that possible? If yes, how?</p>
  
  <p>Thanks!</p>
  
Tags: <routes>
Title: Wildcard subdomain for posts
ThreadText: # Wildcard subdomain for posts
  
  (Asked by: username_0 on 2018-02-02)
  
  I want to assign a wildcard domain to every entry from a specific type. For instance:
  
  `client.example.com`
  
  Where `client` is the slug of an entry. Is that possible? If yes, how?
  
  Thanks!
  
  **Tags:** routes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-02-02. Score: 3
  
  It’s definitely possible. Here’s the gist:
  
  1. Forget the whole subdomain idea, and start by getting everything working using a URI format like `/client/<slug>`.
  2. Make all subdomain traffic get routed to the same server/virtual host.
  3. Make Craft *think* that subdomain requests actually had a URI in the format of `/client/<slug>`, so it will route the request the way it did in step 1.
  
  How you go about the second step depends on whether you’re on Nginx or Apache.
  
  * For **Nginx**, add `default_server` to the server config’s `listen` directive:
  
    ```
    server {
        listen 80 default_server;
        // ...
    }
  
    ```
  * For **Apache**, create a [`_default_` virtual host definition](http://httpd.apache.org/docs/2.0/vhosts/examples.html#default):
  
    ```
    <VirtualHost _default_:*>
        // ...
    </VirtualHost>
  
    ```
  
  Exact details depend on your hosting environment so you may need to do some of your own googling here. You’ll likely need to restart the webserver before changes take effect, too.
  
  Once you have all subdomain traffic routing to the same place, add something like this to your index.php file:
  
  ```php
  <?php
  
  $domainParts = explode('.', $_SERVER['HTTP_HOST']);
  
  if (count($domainParts) === 3)
  {
      $slug = $domainParts[0];
  
      // Fake Craft into thinking the URI was actually /clients/<SLUG>/uri/...
  
      // Nginx:
      $_REQUEST['REQUEST_URI'] = "/clients/$slug".($_REQUEST['REQUEST_URI'] ?? '');
  
      // Apache:
      $_GET['p'] = "clients/$slug/".($_GET['p'] ?? '');
  }
  
  // ...
  
  ```
  
  With that in place, your `client.domain.tld` requests should start serving those client entry pages!
  
  > **Comments:**
  > **username_2**: Looking at the date, I assume that this is for Craft 2. Should this also work for Craft 3?  I have a Structure and would like the level 1 entries to be available at `level-1.example.com` and level 2, 3 etc at `level-1.example.com/level-2`, `level-1.example.com/level-2/level-3`. Also, I'm using Nitro 2 and don't know how to edit the Nginx config. Thanks! (I would prefer not to use multisite if poss.)  
  
  ---
  
  ### Answer by username_2 on 2021-02-25. Score: 1
  
  Craft 3.x and Nitro 2:
  
  In Nitro 2, I added a site alias `level-1.example.nitro` via `nitro alias` and at top of index.php I have:
  
  ```
  $domainParts = explode('.', $_SERVER['HTTP_HOST']);
  $uri = $_SERVER['REQUEST_URI'];
  
  if (count($domainParts) === 3)
  {
      $slug = $domainParts[0];
      $_GET['p'] = "$slug/".($_GET['p'] ?? $uri);
  }
  
  ```
  
  I can visit `level-1.example.nitro` and `level-1.example.nitro/level-2`, `level-1.example.nitro/level-2/level-3` with the expected results.
  
  
  ---
  
  