我通过在cpanel上创建子域app.example.net
将项目部署到了实时服务器上。并将我的项目放在app.example.net
文件夹中。
在我的项目中,我有两个如下的路线组
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
});
});
这是我在项目公用文件夹中的.htaccess文件
<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>
当我转到app.example.net
时,它可以工作,但是当我转到通配符子域时,例如abc.example.net
,则会出现404
错误
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.
如何解决此错误,以便通配符子域也可以工作。