I deployed my project on live server by creating subdomain app.example.net on cpanel. And put my project in app.example.net folder. In my project I have two route groups like below
Routes.php
<?php
Route::group(['domain' => 'app.example.net'], function(){
Route::get('/', function () {
if (auth()->check()) {
return redirect('http://'.session('subdomain').'.example.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}.example.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
});
});
here is my .htaccess file in project's public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
when I go to app.example.net it works but when I go to wildcard subdomain e.g abc.example.net it gives 404 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 resolve this error so that wildcard subdomain also works. Note: I am not creating any subdomain just store subdomain name entry in db and check whether the subdomain entry exist in db , if yes then go to that wildcard subdomain otherwise not found error.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community