在Laravel 9中添加子域

发布于 2025-02-12 15:43:00 字数 1098 浏览 0 评论 0原文

由于某种原因,添加子域路由不起作用,并且不断返回我的主页而不是我需要的页面。我在应用程序中使用了Laravel,interiajs vue。

这是我的路线:

Route::domain('webshopview.localhost:8000')->group(function () {
    Route::get('/webshopview', function () {
        return Inertia::render('Products/Index');
    });
});

我希望能够以WebShopview.localhost:8000访问它,但是每次我尝试访问此路线时,都会返回我的应用主页。如果我像以下示例那样在普通路线上这样做,它就像魅力一样。

Route::get('/webshopview', function () {
    return Inertia::render('Products/Index');
});

为一组路线创建子域的缺少是什么?为什么它不断返回应用主页忽略子域

我的应用程序在'http:// localhost:8000/'和'http://127.0.0.1.1:8000/'上本地工作,并且默认情况下它可以像我这样做任何事情。因此,我想要的只是将子域添加到特定路由上,以便我可以像这个'example.localhost:8000'或'example.127.0.0.1:8000'这样访问。最终结果是在部署'https://www.subdomain.domain.com'

我什至尝试过时,将其显示为这样的路线:

Route::get('/productview', function () {
    return 'First sub domain';
})->domain('productview.localhost');

现在访问'http://productview.localhost/'返回“无法达到此站点”错误。

For some reason adding subdomain route isn't working and keeps on returning my homepage instead of the page I need. I'm using Laravel, Inertiajs Vue in my app.

Here is my route:

Route::domain('webshopview.localhost:8000')->group(function () {
    Route::get('/webshopview', function () {
        return Inertia::render('Products/Index');
    });
});

I want to be able to access it as webshopview.localhost:8000 but every time I try to visit this route it returns my app home page. If I do this in normal route like the below example, it works like a charm.

Route::get('/webshopview', function () {
    return Inertia::render('Products/Index');
});

What is missing to create a subdomain for group of routes? Why it keeps returning the app homepage ignoring the subdomain

My app works locally on 'http://localhost:8000/' and 'http://127.0.0.1:8000/' and it works like that by default without me doing anything. So all I want is to add subdomain to specific routes so that I can access like this 'example.localhost:8000' or 'example.127.0.0.1:8000'. The end result is to have the route displayed like this after deployment 'https://www.subdomain.domain.com'

I even tried this and it didn't work:

Route::get('/productview', function () {
    return 'First sub domain';
})->domain('productview.localhost');

now accessing 'http://productview.localhost/' returns 'This site can’t be reached' error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2025-02-19 15:43:02

我必须手动在Windows上的etc/hosts文件中添加路由,然后重新启动整个计算机才能生效。

I had to manually add the routes in my etc/hosts file on windows and restart the entire machine for it to take effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文