I am trying to setup routing based on the 1st URI segment.
I have a rule:
$route['(:any)'] = pages/view_page/$1;
I want to make my routes conditional so that if a controller of the name of URI segment 1 is called it goes to the controller as normal.
If no controller exists then go to the pages/view_page function.
I have tried wrapping the $route rule with an if statement that checks URI segment 1 and uses that to see if a file exists to match it but this doesn’t seem to work.
Does anybody have any suggestions for how to do this without having to write lots of route configurations.
Since the routing overrides are simple regexp based transformations, you can’t really embed “is that would work otherwise” kind of logic directly. This leaves you with basically two options:
(:any)rule$route['404_override']reserved route instead to indicate what controller should be loaded when no controller found otherwise. However, check the urls comming in and callshow_404()and output proper 404 http status code for missing static assets and such.