2017-04-07 15 views
0

我想將所有人們輸入的錯誤URL(例如,www.website.com/xwfkjdf,不存在的頁面)重定向到登錄頁面(如果他們沒有登錄)和儀表板如果他們已登錄。如何將所有錯誤的URL重定向到登錄頁面?

目前,我得到「NotFoundHttpException」的錯誤。

+0

那麼你的代碼是什麼樣子? –

+1

你可以做到這一點與Handler.php: [https://laracasts.com/discuss/channels/requests/how-can-i-redirect-all-request-of-notfoundhttpexception-to-the-home-page] (https://laracasts.com/discuss/channels/requests/how-can-i-redirect-all-request-of-notfoundhttpexception-to-the-home-page) –

+0

是,@MeeraTank,它只是方式我想了。非常感謝! 這工作:我添加此行到應用程序/ Exceptions/Handler.php文件: if($ e instanceof NotFoundHttpException){ return redirect() - > route('home'); } – chuck

回答

1

更改內部app\Exceptions\Handler.phprender功能

public function render($request, Exception $exception) 
{ 
    //redirect if route is not found 
    if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException){ 
     return redirect('/'); 
    } 
    return parent::render($request, $exception); 
} 
相關問題