我正在使用Laravel 4框架,我定義了一大堆路由,現在我想知道所有未定義的URL,如何將它們路由到404頁面?Laravel默認路由到404頁面
9
A
回答
9
不定路線打響Symfony\Component\HttpKernel\Exception\NotFoundHttpException
例外,你可以在應用程序中處理使用App :: error()方法是這樣/開始/ global.php:
/**
* 404 Errors
*/
App::error(function(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $code)
{
// handle the exception and show view or redirect to a diff route
return View::make('errors.404');
});
6
處理錯誤可以推薦的方法在Laravel文檔中發現:
http://laravel.com/docs/4.2/errors#handling-404-errors
使用App ::失蹤()函數在開始/ global.php文件以下列方式:
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
4
我升級我laravel 4代碼庫Laravel 5,任何人誰在乎:
App::missing(function($exception) {...});
不再在Laravel 5,爲了返回404視圖所有不存在路線,儘量把在應用中的以下/ HTTP/Kernel.php:根據
public function handle($request) {
try {
return parent::handle($request);
}
catch (Exception $e) {
echo \View::make('frontend_pages.page_404');
exit;
// throw $e;
}
}
6
你可以在添加文件:重來源/意見/錯誤/ 調用404.blade.php與您想要在404錯誤上顯示的信息。
+0
本文檔適用於Laravel 5,但是您是對的,而且我最近已將基於Laravel 4.2的項目更新爲Laravel 5.現在如果我想擁有2 404個頁面,一個用於移動設備,另一個用於桌面瀏覽器? – dulan 2015-11-21 06:43:09
17
相關問題
- 1. ASP.NET路由。默認頁面
- 2. URL路由到默認頁面
- 3. 角度默認頁面路由
- 4. Php Laravel 404路由
- 5. 路由默認的404工作不
- 6. asp.net網頁。默認路由
- 7. Laravel默認頁面空白
- 8. Laravel 4:創建一個默認路由
- 9. Angular UI路由器重定向到默認頁面
- 10. ASP.NET和自定義路由到默認頁面
- 11. Laravel PUT路由結果404
- 12. Laravel路由錯誤404
- 13. laravel路由和404錯誤
- 14. 克隆默認的nginx 404頁面?
- 15. 角JS不經過路由的瀏覽器頁面刷新到默認頁面
- 16. Laravel 5.2 - 未定義的路由默認錯誤頁
- 17. 的.htaccess頁面重新路由 - 讓404
- 18. 快速路由 - 根頁面和404
- 19. 在角度ui路由器404頁面
- 20. Restlet默認路由?
- 21. 上默認路由
- 22. 鐵路路由器的默認路由
- 23. 添加路由不失默認路由
- 24. 默認使用Zend路由器路由
- 25. Backbone.js路由條件默認路由
- 26. MVC5路由到404
- 27. Laravel更改默認路徑
- 28. 設置幫助頁面作爲默認路由
- 29. 設置Angular路由的默認開始頁面
- 30. 如何在asp.net webforms中設置默認頁面url路由
從技術上講,當你點擊404路線時,我不會重定向到路線,只是顯示404頁面。 – bgallagh3r 2014-11-06 01:41:16
是這就是我的意圖,不重定向,只顯示404頁面,而你的是正確的,謝謝! – dulan 2014-11-06 01:53:01