在CodeIgniter中重写URL [英] Rewrite URLs in CodeIgniter

查看:78
本文介绍了在CodeIgniter中重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在CodeIgniter中重写以下网址

  localhost / users / show_profile / john 

  localhost / john 

感谢

解决方案

,您可以使用 CodeIgniter路线实现动态网址。



假设
localhost / users / show_profile / john



我们正在看:

  localhost / controller / method / variable 
pre>

我们可以使用以下路由:

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

您可以通过调用 $ this-> uri-> ; segment(1);



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


How can I rewrite the following urls in CodeIgniter

localhost/users/show_profile/john

to

localhost/john

Thanks

解决方案

you can achieve dynamic URL using CodeIgniter Routes.

Assuming localhost/users/show_profile/john

We're looking at:

localhost/controller/method/variable

we can use the following route:

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

You can access the variable by calling $this->uri->segment(1); inside show_profile() function.

IMPORTANT: keep the $route['([a-zA-z_]+)'] at the end of the routes.php file, to make sure it's not overriding any other routes.

这篇关于在CodeIgniter中重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆