Oyed
501
8
Laravel

Subdomain + CNAME routing

Posted 3 years ago by Oyed

I have my routes set up as follows:

<?php

Route::group([
    'domain' => '{username}.u.'.env('APP_DOMAIN'),
], function () {
    Route::get('/', '[email protected]');
});

Route::group([
    'domain' => env('APP_DOMAIN'),
], function () {
    // Regular site routes
});

Route::group([
    'domain' => '{domain}',
], function () {
    Route::get('/', '[email protected]');
});

What I'm trying to achieve is allowing users to have their own sites, e.g. hello.u.domain.com, and for those sites to also be served through a custom domain that is CNAME'd to their subdomain. Using the routing above, the wildcard subdomain works perfectly fine. However the custom domain routing is never hit; whenever a custom domain that is CNAME'd to the subdomain is visited, the regular site routes are used.

APP_DOMAIN is not the same as the custom domain, and I have $router->pattern('domain', '[a-z0-9.]+'); in my RouteServiceProvider.php to allow {domain} as a full domain name.

Please sign in or create an account to participate in this conversation.