如何在 codeigniter 中删除 url 中的控制器名称

how to remove controller name in url in codeigniter

我目前URL是

http://myaliveidea.com/news/detail/hello/71/In-Ireland-hiking-for-ancient-relics-hidden-by-fog

然后我想删除控制器名称 在此 URL 中,控制器名称为 == detail 和函数名称 id = hello

所以我希望我的 URL 像这样 http://myaliveidea.com/news/hello/71/In-Ireland-hiking-for-ancient-relics-hidden-by-fog

application/config/routes.php中,像这样重写url:

$route['news/hello/(:num)/(:any)'] = "news/detail/hello//";

我不确定 news 部分,如果它是控制器文件夹中的子文件夹,那么上面的行就可以了,如果 CI 安装在 news 子文件夹中,那么请把两边的news部分去掉。

确保接受来自 hello 方法的参数值,如下所示:

public function hello($id = null, $slug = null)

可以用routes改变uri路径,这里有documentation

在 routes.php 中尝试此代码:

$route['hello/(:any)'] = "detail/hello//";

or 

$route['hello/(:num)/(:any)'] = "detail/hello//";