i made simple resume site with laravel 5.4 and i wanna if users type anything except my site name and my site.com/panel automatically redirect to 404 page.
how can i do that?
is there any route to do that or what?
i found this code but not use
public function render($request, Exception $e)
{
if ($e instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException){
return response(redirect(url('/')), 404);
}
return parent::render($request, $e);
}
just add abort
method
return abort(404);
it's automatically redirect to your resources/views/errors/404.blade.php
return abort(404);
并通过获取请求为这个特定的操作/方法设置你的路线。
此外,您可以提供响应文本:
return abort(403, 'Unauthorized action.');
you can create a view in
resources/views/errors/404.blade.php
and it will redirect every unexist route that you didn't include it in
web.php
and in 404.blade file you can put this hyper link to redirect use to your home page either by choosing route name
<a href="{{ route('home') }}">Back to home</a>
or by specifying a route link directly
<a href="/">Back to home</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.