不一致的 CodeIgniter routes.php 行为

Inconsistent CodeIgniter routes.php behaviour

我正在使用 CodeIgniter 的 routes 文件将短 URL 重新映射到它们的相关控制器功能。

奇怪的是,有些网址会重新映射,而另一些则不会,即使语法相同。

下面是我的 routes.php 文件。 info/webinfo/rent 的重新映射按预期工作,而 info/cellinfo/hotel 被重定向到我的 404 函数。

知道是什么原因造成的吗?

$route['default_controller'] = "home";
$route['404_override'] = 'home/four_o_four';
$route['robots.txt'] = 'home/robots';

$route['info/cell'] = "articles/tags/cellphone";
$route['info/rent'] = "articles/tags/car-rental";
$route['info/web'] = "articles/tags/internet-abroad";
$route['info/hotel'] = "articles/tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/";
$route['articles/destination/(:any)'] = "articles/articles_by_destination/";
$route['articles/(:any)'] = "articles/show_article/";

您正在将一个 URI 重新路由到另一个重新路由的 URI。

$route['info/cell']            = "articles/tags/cellphone";
$route['info/rent']            = "articles/tags/car-rental";
$route['info/web']             = "articles/tags/internet-abroad";
$route['info/hotel']           = "articles/tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/";

你应该路由一个URI一个 Controller/Method,而不是另一个 URI。

只需将它们全部直接路由到每个对应的Controller/Method...

$route['info/cell']            = "articles/articles_by_tags/cellphone";
$route['info/rent']            = "articles/articles_by_tags/car-rental";
$route['info/web']             = "articles/articles_by_tags/internet-abroad";
$route['info/hotel']           = "articles/articles_by_tags/hotel";
$route['articles/tags/(:any)'] = "articles/articles_by_tags/";

Routes Documentation