How to handle www and wildcard subdomain with laravel subdomain routing
My website is running on root domain www.example.com, and also I have wildcard subdomain as * for all user's store page. I have already added DNS records on my domain for both www.example.com and *. example.com and both are pointing to same ip which is my server where I have hosted my laravel project. So basically I have a url https://www.example.com when I hit this url it open my site homepage but if I hit the url https://ajay01.example.com it should open the profile of user ajay01 which is unique for each user and stored in database. If record is exists then it will open the profile page but if not then redirect to 404 not found.
So, my root domain homepage route is like this.
Route::get('/', 'Home\HomeController@getLatestHomePage')->name('homepage');
And this is subdomain routes.
Route::group(['domain' => '{creatorSlug}.' . config('app.domain')], function () {
Route::get('/', array('uses' => 'Creator\StorefrontController@index'));
});
I have added my subdomain route above my main homepage route so that it prevent root domain routes from overwriting subdomain routes. Now the issue is it works fine with the subdomain route but when I hit root domain route the https://www.example.com it throw 404 not found, because it actually calling subdomain route for www also. how do I solve this?
Please or to participate in this conversation.