PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] How to direct random routing (404) to one view page in laravel?

 January 26, 2022     httprequest, laravel, laravel-5, php     No comments   

Issue

I want to direct random link to only one view except that I've define

e.g : localhost:8000/abxcdss

It will go to a view or home page.


Solution

Solution #1 - Via Exception Handler (404)

app/Exceptions/Handler.php

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

//

public function render($request, Exception $exception)
{
    if ($exception instanceof NotFoundHttpException) {
        return redirect('/');
    }

    return parent::render($request, $exception);
}

Solution #2 - Via Route

routes/web.php

// Last line!

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


Answered By - Wahyu Kristianto
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing