If I want to catch every single non existing URL that was passed to my web application and serve them a view without serving a 404, how would I do that?
Essentially I need to record the statistics based on these hits, but I need to do it by serving content and not a 404 error.
As far as I can tell from application/config/routes.php
, I could use
$route['default_controller'] = 'catchall';
but I need that for my actual web application.
I could also use
$route['404_override'] = 'catchall';
but I don't want to throw 404s.
I tried using
$route['(:any)'] = '$1';
but I need to record the entire URL (e.g. any length of segments), not just the first segment.
UseRouting adds route matching to the middleware pipeline. This middleware looks at the set of endpoints defined in the app, and selects the best match based on the request. UseEndpoints adds endpoint execution to the middleware pipeline. It runs the delegate associated with the selected endpoint.
MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); The route names give the route a logical name. The named route can be used for URL generation. Using a named route simplifies URL creation when the ordering of routes could make URL generation complicated.
Routing is used to map requests to route handlers. Routes are configured when the application starts up, and can extract values from the URL that will be used for request processing.
Basic Controllers You can define a route to this controller method like so: use App\Http\Controllers\UserController; Route::get('/user/{id}', [UserController::class, 'show']);
Use $route['(:any)'] = 'catchall_controller'
. Then in your controller you can access the URI segments using $this->uri->segment(n)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With