CodeIgniter - 删除“索引"来自网址

2022-01-02 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 路由

相关文章