# Domain and subdomain routing

**URL:** <https://discourse.slimframework.com/t/domain-and-subdomain-routing/1241>\
**Category:** Questions\
**Created:** [March 6, 2017, 9:24am UTC](https://discourse.slimframework.com/t/domain-and-subdomain-routing/1241 "2017-03-06T09:24:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gricey](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@gricey](https://discourse.slimframework.com/u/gricey)\
**Post date:** [March 6, 2017, 9:24am UTC](https://discourse.slimframework.com/t/domain-and-subdomain-routing/1241/1 "2017-03-06T09:24:43Z")

</div>

I’m trying to make an app that includes routing on the subdomain. I’ve seen the response at [Subdomains control for url in slim](http://discourse.slimframework.com/t/subdomains-control-for-url-in-slim/24) but it seems a bit messy to have what’s essentially my routing logic split between two different systems (nginx & slim).

I was looking at how laravel does it but can’t come up with a semi-neat workaround for slim.  
The goal would be code like

```
// Based on laravel
$app->group(array('domain' => 'example.com'), function($request, $response) use ($app) {

    $app->get('/', function($request, $response) {
        $response->getBody()->write("Welcome to the splash page for our product");
        return $response;
    });

});

$app->group(array('domain' => 'admin.example.com'), function($request, $response) use ($app) {

    $app->get('/', function($request, $response) {
        $response->getBody()->write("Admin page with some functions");
        return $response;
    });

});

$app->group(array('domain' => '{client}.example.com'), function($request, $response) use ($app) {

    $app->get('/', function($request, $response) {
        $client = $request->getAttribute('client');
        $response->getBody()->write("Welcome to your app " . $client);
        return $response;
    });

});

```

Any ideas on how to achieve this kind of neatly, or if it’s possible?  
Cheers

---

<div class="post-metadata">

**Author:** ![geggleto](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/geggleto/32/11_2.png) [@geggleto](https://discourse.slimframework.com/u/geggleto)\
**Post date:** [March 6, 2017, 5:25pm UTC](https://discourse.slimframework.com/t/domain-and-subdomain-routing/1241/2 "2017-03-06T17:25:46Z")

</div>

Currently not possible.
