簡體   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