Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Laravel subdomain routes do not work for mapped domain

I am building a multi-tenant application using Laravel. The system works perfectly to handle subdomains hosted on my main domain. That is, my application can serve any subdomain {subdomain}.my.app.

The problem however occurs when I map a subdomain to it. That is if I configure CNAME for my customer's domain:

subdomain.customer.app ---->maps to---> subdomain.my.app

Then laravel fails to recognize the route. Here's how I am handling routing (and it works perfectly on my local machine running valet)

Route::middleware('appendSubdomainInfo')->domain('{subdomain_slug}' . '.'. config('app.primary_domain'))->group(function () {
    
    Route::middleware('subdomainAccessChecker')->group(function() {

        // All my subdomain routes go here. 
        Route::get('/check', function($subdomain_slug) {
            dd($subdomain_slug);
        });

    });
});

The above code throws correct output subdomain when accessed on subdomain.my.app/check; but throws 404 error when run on subdomain.customer.app/check.

I'm using CNAME mapping on customer.app as:

CNAME | subdomain | subdomain.my.app. | 600

Can someone help me figure out how to fix this?

0 likes
1 reply
thebigk's avatar
Level 13

Update: The AI provided solution was incorrect. Can a human help me out here?

Please or to participate in this conversation.