Laravel 8处理子域路由,但它不起作用,我对此有些困惑
我正在研究一个项目,每个用户将有单独的子域,例如我的网站名称是xyz.com,然后对于用户,它将是user.xyz.com,因为我试图进行子域路由,但它不起作用。
以下是以下主要领域的路线
Route::get('/', function () {
return redirect('login');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
是子域的路线
Route::domain('user.xyz.com')->group(function () {
Route::get('/posts', function () {
return 'Second subdomain landing page';
});
});
任何专家,请研究一下。 欢迎建议。
I'm working on a project where for each user there will be separate subdomain for example my website name is xyz.com then for user it will be user.xyz.com, for that im trying to do subdomain routing but its not working.
Below are the routes for main domain
Route::get('/', function () {
return redirect('login');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Below are routes for subdomain
Route::domain('user.xyz.com')->group(function () {
Route::get('/posts', function () {
return 'Second subdomain landing page';
});
});
Any expert please look into this.
Suggestions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个建议...为什么不将域作为参数传递,以您未知的方式,例如
/article/article/{id}
的文章ID?尝试以下操作:
在我们的
post -scontroller
输出结果...让我知道它是否适合您。
I have a suggestion... why not pass the domain as a parameter the way you would an unknown, article id for example
/article/{id}
?Try this:
In our
PostsController
output the results...Let me know if it works out for you.
尝试在RouteserviceProvider中添加域线。
Try to add a domain line in RouteServiceProvider.