CodeIgniter-维护复杂的URL路由


CodeIgniter - Maintain complex URL routing

我想在路由时维护一个复杂的URL结构。我无法为以下要求编写路由。

如果URL带有http://localhost/api/cals/func/id,我想将其路由到http://localhost/api/cals/func/id,否则我想将URL路由到http://localhost/home/

我尝试过这个,但它并不是在所有用例中都有效。

$route['api/(:any)'] = 'api/(:any)';
$route['(:any)'] = 'home/index/';

为什么会这样?

这可能会对您有所帮助;你必须使用$1

$route['default_controller'] = 'home/index/';
$route['api/(:any)'] = 'api/$1';
$route['(:any)'] = 'home/index/';