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

habib997's avatar

deployment of laravel wildcard subdomain app on shared hosting server causing error

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.

0 likes
12 replies
Sinnbeck's avatar

First you need to ensure that your web host points the wildcard to the laravel installation. This does not sound like it has been done. They need to change it on apache/nginx

Sinnbeck's avatar

Sure. Call or send an email to your provider and ask them to set it up

hi. I would like you to set by website to respond to *.client.net. My website is located at client.net

Something like that should do it

habib997's avatar

@sinnbeck my website is at app.client.net and my wildcard subdomain routes are in that app.client.net as I showed above code. It is only one app that running app.client.net routes and wildcard subdomain routes. I hope you may get me point. I will contact my provider and then see what they say

Sinnbeck's avatar

Yeah I get it. The thing is this. For this to work you need 3 things

  1. Point the wildcard subdomain to the correct ip (I assume you have done this)
  2. Make sure the server knows which website should handle the subdomains (this I assume have only been done for app.client.net and client.net, not *.client.net)
  3. Set it up in your routes in laravel (this I know you have done) :)
Snapey's avatar

You need to create a DNS entry on the domain so that all subdomains point to the same website. This is in addition to making the web server respond to all those domains.

Frankly, in shared hosting, you are probably out of luck having influence regarding the web server.

habib997's avatar

@sinnbeck yes it is loading the image but when I access anysubdomain.client.net it throws 403 error and sometimes 404. I think It is assuming that another copy of project should be in wildcard subdomain folder but that's not I want. how to do step 2

obiiarticle's avatar

Our blog post is a helper document for novice Laravel developers trying to set up a Laravel app on a shared server. We will be posting a helper document for deploying a Laravel app on Cloud instances shortly.

Please or to participate in this conversation.