0

I want to create default route for wrong url in laravel.if I have typed tst instead of test It should redirect to default url '/' is it possible to restrict wrong url in laravel I have the routes

Route::get('/', function () {
    return view('welcome');
});
Route::get('/test', function () {
    return view('welcome');
});
user3386779
  • 6,883
  • 20
  • 66
  • 134
  • 1
    Possible duplicate of [Redirect to homepage if route doesnt exist in Laravel 5](https://stackoverflow.com/questions/29479409/redirect-to-homepage-if-route-doesnt-exist-in-laravel-5) – julianstark999 Dec 20 '17 at 05:38
  • Check here https://laracasts.com/discuss/channels/general-discussion/how-do-i-create-a-custom-404-error-page – Deepak Kumar T P Dec 20 '17 at 05:39
  • This is not the solution, but just want to share that In laravel 5.5, error page now has it's own template. So need to worry about error page. – Vandolph Reyes Dec 20 '17 at 05:49

1 Answers1

2

At the end of all routes, add following route:

Route::any('{any}', function () {
    return redirect()->url('/');
});

Or you can write directly like:

Route::redirect('/{any}', '/', 301);

This will take any routes except listed one and redirect to url.

Sovon
  • 1,804
  • 1
  • 22
  • 30