繁体   English   中英

使用laravel的通配符子域

[英]Wildcard subdomains using laravel

我正在尝试将www.example.com/username更改为username.example.com。 我已经设置了Apache,现在我已经陷入困境了。 在我的userController中,我得到了这个,并且它适用于www.example.com/username

if($validator->passes() && Auth::attempt($userdata)) {
    return Redirect::to(Auth::user()->username)->with('flash_notice', 'You have logged in successfully');
}

现在我在routes.php中得到了这个,但什么也没做。 感谢您的时间。

Route::group(array('domain' => '{account}.example.com'), function()
{

Route::get('{account}', function($account, $id)
{
    $account = Input::get('username');
    $id = Input::get('id');
});

});

您现在想要路由到域的根目录,而不是'{account}' 只需使用/作为您的路线:

Route::group(array('domain' => '{account}.example.com'), function()
{
    Route::get('/', function()
    {
        $account = Input::get('username');
        $id = Input::get('id');
    });
});

此外,您的重定向需要重定向到子域:

return Redirect::to('https://' . Auth::user()->username . '.example.com')
           ->with('flash_notice', 'You have logged in successfully');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM