Check this: https://laraveldaily.com/wildcard-subdomain-in-routes-assign-subdomain-for-every-user/
search medium.com also they have articles.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have searched all the questions related to my questions on StackOverflow but didn't find any solution. I have developed a laravel wildcard subdomain project and is working good on localhost now it is causing problems on wildcard subdomains when I deployed the project on server.here is my project route.php file
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
*/
Route::group(['domain' => 'app.client.net'], function(){
Route::get('/', function () {
if (auth()->check()) {
return redirect('http://'.session('subdomain').'.client.net/home');
}
return view('welcome');
})->name('homepage');
Route::get('/register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('/register', 'Auth\RegisterController@register');
Route::get('/login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('/login', 'Auth\LoginController@login')->name('login');
Route::get('/setupCompany', 'CompanyController@setupCompanyForm')->name('setupCompanyForm');
Route::post('/setupCompany', 'CompanyController@setupCompany')->name('setupCompany');
Route::get('/register/verify', 'CompanyController@verfiy')->name('registerVerify');
});
Route::group(['domain'=> '{subdomain}.client.net', 'middleware' => 'checkSubdomain'],function () {
Route::get('/', 'Auth\CompanyLoginController@showLoginForm')->name('companyLogin');
Route::post('/', 'Auth\CompanyLoginController@login')->name('companyLogin');
Route::group(['middleware' => 'customAuth'],function(){
Route::get('/home', 'HomeController@index')->name('home');
Route::post('/logout', 'Auth\LoginController@logout')->name('logout');
Route::post('/inviteClient', 'HomeController@inviteClient'); //ajax req
Route::get('/profile', ['as' => 'profile.edit', 'uses' => 'ProfileController@edit']);
Route::put('profile', ['as' => 'profile.update', 'uses' => 'ProfileController@update']);
Route::put('profile/password', ['as' => 'profile.password', 'uses' => 'ProfileController@password']);
Route::get('/getClients', 'HomeController@clients'); //ajax req
});
});
I have the following routes. app.client.net for user registration and wildcard subdomain *.client.net for logged in users. In my app user registers himself through app.clients.net and logged in and redirect to its wildcard subdomain. It is working properly on localhost but not on live server. I deployed it on a live server by making app.client.net subdomain on a server and deployed project there then wildcard subdomain {subdomain}.client.net is not working. when I go to app.client.net it is working properly but when I go to wildcard subdomain e.g abc.client.net it gives the following error.
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
how to configure this so that static subdomain(app.client.net) and wildcard subdomain({subdomain.client.net}) both can work? Note: I am not creating any subdomain on the server it is just database entry which checks subdomain exists in the database if it does then it uses it as a wildcard subdomain. I am on shared hosting and I do not have httpd.conf file access.
Please or to participate in this conversation.