在Laravel中使用模式匹配除主域和www以外的所有域

在Laravel中使用模式匹配除主域和www以外的所有域,laravel,Laravel,我有一个允许用户选择子域或添加自己的自定义域名的设置。问题是我的一些路线“冲突”。其中之一是/路线 首先,我在所有基本路由周围添加了一个域组,只过滤掉我的域名。以下是该版本: // Base routes Route::domain(config('app.domain')->group(function () { Route::get('/', 'HomeController')->name('home'); }); // Profile routes Route::do

我有一个允许用户选择子域或添加自己的自定义域名的设置。问题是我的一些路线“冲突”。其中之一是
/
路线

首先,我在所有基本路由周围添加了一个域组,只过滤掉我的域名。以下是该版本:

// Base routes
Route::domain(config('app.domain')->group(function () {
    Route::get('/', 'HomeController')->name('home');
});

// Profile routes
Route::domain('{profileUrl}')->group(function () {
    Route::get('/', 'UserController@show')->name('users.show');
});
但是基本路由不匹配
www.domain.com
。这让我觉得我应该以某种方式使用regex将domain+
www
从配置文件路由中排除。也就是说,基本路线将作为后备路线。因此,我将路线改为:

// Profile routes
Route::domain('{profileUrl}')->group(function () {
    Route::get('/', 'UserController@show')->name('users.show');
});

// Base routes
Route::get('/', 'HomeController')->name('home');
并尝试通过注册如下模式排除路由:

\Route::pattern('profileUrl', '^(?!(domain\.com|www\.domain\.com)$).*');
但是由于Laravel路由器使用
Str::is()
来匹配模式,所以正则表达式不起作用

我知道我可以使用nginx解决这个问题,但这需要配置所有prod+staging+dev服务器。我宁愿把它放在我的代码库中

如何匹配Laravel路由器组中除主域和www子域之外的所有请求