We are migrating an old Laravel 4.2 app to Laravel 7.
When we first built the app several years ago, we created a db table of old URLs and their new paths so as to avoid google giving a 404. So if a user typed in www.website.com/old_address they would be automatically redirected to www.website.com/new_address.
In L4.2. we had the following code in app\start\global.php
App::missing( function(Exception $exception) {
$p = Request::path();
$r = ThreeO1Redirect::checkRedirect( $p ); //Just does a simple where search.
if ($r) {
RedirectHistory::createNew($p);
return Redirect::to( $r->new_address, 301);
}
FourOFour::logError();
return Response::view("404", [], 404);
});
In L7 we have added the following to app\Exceptions\Handler.php
//If it's a route not found, see if there is a redirect in the redirects table.
if ($exception instanceof NotFoundHttpException) {
$p = request()->path();
$r = ThreeO1Redirect::checkRedirect($p); //Simple where search.
if ($r) {
return redirect($r->new_address, 301);
}
}
This works fine if the old address is something like 'articles'.
However, if the old address includes a php file extension (i.e. 'about_us.php') it fails with an error:
No input file specified.
I think Laravel is just looking for the specified file in the public dir. But i want it to treat this the same as any other route.
Any ideas??
Thanks