重写CodeIgniter中的URL

时间:2011-06-02 20:04:57

标签: codeigniter

如何在CodeIgniter中重写以下网址

localhost/users/show_profile/john

localhost/john

由于

3 个答案:

答案 0 :(得分:2)

您可以使用CodeIgniter Routes实现动态网址。

假设 localhost/users/show_profile/john

我们正在寻找:

localhost/controller/method/variable

我们可以使用以下路线:

$route['([a-zA-z_]+)'] = "users/show_profile/$1";

您可以通过调用show_profile()函数内的$this->uri->segment(1);来访问变量。

重要提示:$route['([a-zA-z_]+)']保留在routes.php文件的末尾,以确保它不会覆盖任何其他路由。

答案 1 :(得分:1)

如果您只需要为一组已定义的URL执行此操作,请更新/config/routes.php

如果您需要它是动态的,那么您应该扩展CodeIgniter路由器库。

http://codeigniter.com/user_guide/general/creating_libraries.html(寻找扩展原生图书馆

答案 2 :(得分:0)

config/routes.php添加$route['(:any)'] = "users/show_profile/$1";
有关路线here

的更多信息
相关问题