recent post

Easy way to find Facebook Page Categories
Easy way to find Facebook Page Categories

How to redirect broken pages to home page in Laravel website...
How to redirect broken pages to home page in Laravel website

Corona: Creativity or captivity for us??
Corona virus has become the pandemic virus in the world. Day by day it is spread...

The first vaccine of COVID-19 has gone to the stage of produ...
Russia has invented the first covid-19 vaccine. This vaccine has invented by the...

High Tech Kitchen Gadgets You Need in 2020
We know time a very important for us. We don’t want to waste our time. In our mo...
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
0 Comments