Every time while we do a Laravel project we face a issue. Such as if your enter this type of url "www.exmple.com/4567usdfhfsd". You will see error or 404 page. So, you can just redirect all this unnecessary link buy redirection them. So, what we need to do?
First you need to go to your {Laravel App}/app/Exceptions/Handler.php
Then find the public function render. You will see this code.
public function render($request, Throwable $exception) { return parent::render($request, $exception); }
You need add this line :
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { return redirect('/'); }
So, The Code will be like :
public function render($request, Throwable $exception) { if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { return redirect('/'); } return parent::render($request, $exception); }
And we are done. Now if you enter "www.exmple.com/4567usdfhfsd". this type of url it will redirect to "www.exmple.com".
Thank you
Onecodesoft Team