Php Codeigniter URL路由问题

Php Codeigniter URL路由问题,php,apache,codeigniter,mod-rewrite,codeigniter-routing,Php,Apache,Codeigniter,Mod Rewrite,Codeigniter Routing,我想知道如何使用Codigniter MVC框架完成以下工作: 我希望我的站点上的URL如下所示: http://www.example.com/florida/miami/12345-selling-a-new-ipod.html http://www.example.com/texas/houston/21345-nice-red-car-for-sale.html http://www.example.com/north-carolina/hickory/92634-giving-away

我想知道如何使用Codigniter MVC框架完成以下工作:

我希望我的站点上的URL如下所示:

http://www.example.com/florida/miami/12345-selling-a-new-ipod.html
http://www.example.com/texas/houston/21345-nice-red-car-for-sale.html
http://www.example.com/north-carolina/hickory/92634-giving-away-two-kitties.html
因此,URI基本上由state/city/article组成

我想覆盖50个州的所有城市,但我不想为每个州和每个城市编写控制器

所以我的问题基本上是:

我如何编写一个控制器来显示基于第一个URI段的状态索引,以及第二个控制器来显示基于第二个URI段的城市索引

致意


Tom

您可以在Apache中使用mod_rewrite来进行URL重写。在共同点火器的文件中。基本上,您必须定义正则表达式才能将
/arg1/arg2/arg3
重写为url
您的\u controller/state=arg1&city=arg2&value=arg3

mod_rewrite的详细信息可以在

中找到,您可以通过在
config/routes.php

$route['^(:any)/(:any)'] = "some_controller/some_method/$1/$2";
这会将所有内容映射到some_控制器类的some_方法函数中。
因此,如果您有任何其他不是example.com/state/city的内容,它也会被发送到那里。。您必须使用另一个路由将其路由出去。

但正则表达式将非常庞大<代码>(佛罗里达州|北卡罗来纳州|南卡罗莱纳州|德克萨斯州|…)等50个州?设置控制器名称,例如美国/州|名称/城市/详细信息