Wildcard subdomain for posts 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!
It’s definitely possible. Here’s the gist:


Forget the whole subdomain idea, and start by getting everything working using a URI format like /client/&lt;slug&gt;.
Make all subdomain traffic get routed to the same server/virtual host.
Make Craft think that subdomain requests actually had a URI in the format of /client/&lt;slug&gt;, 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:

&lt;VirtualHost _default_:*&gt;
    // ...
&lt;/VirtualHost&gt;



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:

&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'] ?? '');
}

// ...


With that in place, your client.domain.tld requests should start serving those client entry pages!