【问题标题】:Laravel 5.5 Routing and Sub-domain RoutingLaravel 5.5 路由和子域路由
【发布时间】:2018-03-01 11:58:21
【问题描述】:

我是 Laravel 的新手。我目前在 Laravel 5.5 上创建了我的个人网站并上传到 GoDaddy 服务器:http://bhattraideb.com/。现在,当我从导航中单击“博客”时,我想像 http://blog.bhattraideb.com/ 这样重定向,目前正在重定向到“bhattraideb.com/public/blog”。

再次从同一个链接“bhattraideb.com/public/blog”单击“恢复”时,我会重定向到“bhattraideb.com/

这是我的路线代码

//** 恢复路由

Route::prefix('/')->group(function() {
    Route::get('/', 'Frontend\ResumeController@index')->name('resume.index');
    Route::resource('resume', 'Frontend\ResumeController');
});

//** 博客路径

Route::get('show/{id}', 'Frontend\PostController@show')->name('post.show');
Route::get('blog/{slug}', ['as' => 'post.single', 'uses' => 'Frontend\PostController@getSingle'])->where('slug', '[\w\d-\_]+');
Route::resource('blog', 'Frontend\PostController');

谁能指导我。

提前致谢。

【问题讨论】:

    标签: php laravel-5


    【解决方案1】:

    您可以阅读https://laravel.com/docs/5.5/routing#route-group-sub-domain-routing 了解更多详细信息,但以下简单示例应该可以工作:

    web.php

    Route::group(["domain" => "blog.bhattraideb.com" ], function () {
         Route::get("/", "Frontend\PostController")->name("blog.index"); 
         //All blog routes should be defined in here
    });
    

    然后,您可以在生成博客链接时使用帮助程序 route("blog.index") 获取 URL 以及子域。

    请注意,您需要将网络服务器设置为接受blog.bhattraideb.com 作为bhattraideb.com 的别名。然后 Laravel 会整理剩下的部分

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 1970-01-01
      • 2017-11-17
      • 2018-06-23
      • 2019-04-02
      • 2020-01-04
      • 2016-09-18
      • 2016-09-25
      • 2015-09-10
      相关资源
      最近更新 更多