1

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.

4

1 回答 1

1

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:

  1. (:any)在“catch all”规则之前列出您要明确工作的路线
  2. 使用$route['404_override']保留的路由来指示当没有找到控制器时应该加载哪个控制器。但是,请检查传入的 url,并调用show_404()并输出正确的 404 http 状态代码以查找缺少的静态资产等。
于 2012-09-18T18:03:59.953 回答