CodeIgniter - 删除“索引";从网址

2022-01-08 00:00:00 url routing php codeigniter controller

注意:我不是在谈论删除 index.php - 我的意思是 index - 方法名称.

NOTE: I'm not talking about removing index.php - I mean index - the method name.

我当前的网址如下所示:

My current URL looks like this:

www.mysite.com/view-topic/index/my-topic

这就是我想要的样子:

wwww.mysite.com/view-topic/my-topic

我该怎么做呢?

提前致谢!

推荐答案

你可以为此设置路由,在application/config/routes.php中,添加一个新行:

You can set up the routes for this, in application/config/routes.php, add a new line:

$route['view-topic/(:any)'] = 'view-topic/index/$1';

这将路由您的 URL http://url.com/view-topic/anythinggoeshere 将屏蔽 view-topic/index/anythinggoeshere 控制器.

This will route your URL http://url.com/view-topic/anythinggoeshere will mask the view-topic/index/anythinggoeshere controller.

更多关于路由的信息:

  • 使用 Codeigniter 进行路由

相关文章