路由问题 - 代码点火器


Routing Issue - Codeigniter

我有基于URI从数据库生成的页面。功能应该如此,但是我无法设置我的routes以消除 URL 中的控制器和功能。

$route['studios/(:any)'] = 'studios/location/$1';

现在,我有显示控制器名称和 URI 变量(无论可能是什么)的路由。但是,我也想删除控制器名称,只显示称为 URL 的 URI 变量。很难解释 - 希望有人能捡起我的漂移......

当前网址为:domain.com/studios/studio1

但我只想显示:domain.com/studio1

我尝试了$route['/(:any)'] = 'studios/location/$1';,但这搞砸了我的整个网站。

帮助?

$route['studios(/:any)*'] = 'studios/location';

这条路线将迫使从studiosstudios/location的一切。然后,您可以使用 URI 段访问任何参数:

$id = $this->uri->segment(2);

如果您的 URL somewhere.com/studios/location/2$id将解析为2

但是,由于您希望它只是从根开始,因此您必须将覆盖路由放在路由文件的底部,以便最后评估它:

// all other routes here. Which must be specifically 
// defined if you want a catch all like the one you mentioned
$route['(:any)'] = 'studios/location';

或者,如果您想要一个高维护站点,您可以指定路由集合,如下所示:

$route['(studio1|studio2|studio3)'] = 'studios/location/$1';

是如何"搞砸你的网站"的?

在任何情况下,您都不应该在/之前 (:any)

只:

$route['(:any)'] = 'studios/location/$1';

编辑:

在$route['(:any)']之前,您需要指定所有控制器的路由;这是很正常的,不知道我是否称其为"高维护",但您需要决定