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

melker's avatar

Route wildcard subdomains on Forge server

Hi!

I have an app with wildcard subdomain routes. I also have A Records for * pointed at the correct IP.

The problem is that when use a subdomain I don't get the route wildcard, but end up on the naked domain root.

web.php

Route::domain('{item}.example.test')->group(function() {
    Route::group(['namespace' => 'Example'], function() {
        Route::get('/', 'ExampleController@show')->name('example.show'); // This is where i want to go
    });
});

Route::get('/', function() {
    return view('welcome'); // This is where I end up
});

Please ask if something is unclear.

Thank you!

0 likes
1 reply
melker's avatar
melker
OP
Best Answer
Level 6

Solved!

Obviously the production domain is not "example.test", so I created an environment variable called APP_DOMAIN and set it to example.test on dev and to the production domain on the server. Then changed web.php thusly:

Route::domain('{item}.' . env('APP_DOMAIN'))->group(function() {
    Route::group(['namespace' => 'Example'], function() {
        Route::get('/', 'ExampleController@show')->name('example.show');
    });
});

Route::get('/', function() {
    return view('welcome');
});

Please or to participate in this conversation.