English 中文(简体)
密码查询
原标题:Codeigniter URL routing question

我很想知道,如何利用Cdigniter MVC框架完成以下工作:

我希望,在我的网站上的URLs也这样做:

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基本上由州/市/条款组成。

我想涵盖50个州的所有城市,但我不想为每个州和每个城市写一名控制员。

因此,我的问题是:

我怎么能写一只控制器,显示基于世界投资倡议第一期内容的国家指数,以及显示基于第二个世界投资倡议部分的城市指数的第二次控制器?

最佳做法

纽约总部

最佳回答

您可以通过在<代码>config/routes.php上配置一条路线来做到这一点。

$route[ ^(:any)/(:any) ] = "some_controller/some_method/$1/$2";

which will map everything into the some_method function of your some_controller class. so if you have anything else which isn t example.com/state/city it will also get sent there.. you would have to route it out of there with another route.

问题回答

You can use mod_rewrite in Apache to do the URL rewrite. In the document of CodeIgnitor http://codeigniter.com/wiki/mod_rewrite/ . Basically, you have to define the regular expression to rewrite /arg1/arg2/arg3 to url your_controller/state=arg1&city=arg2&value=arg3 Details of mod_rewrite can be found at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签