codeigniter routes

北战南征 提交于 2019-12-23 06:07:52

问题


need next: I use codeigniter 2.02 I removes index.php with htaccess

I have controller post and with route

$route['(:any)'] = "post/index/$1";

And I get what I want: domain.com/14 in place of domain.com/post/14

BUT now I have next controllers that I want like: login, member etc.

But if I go to domain.com/login I'm redirected to domain.com ... so if someone can get me solution so I can go to login controller... with some regular expression with routes!

this is my routes:

$route['default_controller'] = "index";
$route['404_override'] = '';
$route['(:any)'] = "post/index/$1";
$route['signup/(:any)'] = "signup/index/$1";

and hier is what effect I need:

domain.com/camera-33455-cannon-2001
domain.com/samsung-6678-new-gallaxy-2

and also to get other controllers like

domain.com/signup

tnx


回答1:


The routes are handled in the order in which they appear on your routes.php file. So if you put your controllers on top, (:any) should just handle anything that is not previously handled.

Try changing it to:

$route['default_controller'] = "index";
$route['404_override'] = '';
$route['signup/(:any)'] = "signup/index/$1";
$route['(:any)'] = "post/index/$1";



回答2:


Do you only want numbers for the post/index route? You might be better off using this:

$route['default_controller'] = "index";
$route['404_override'] = '';
$route['signup/(:any)'] = "signup/index/$1";
$route['(:num)'] = "post/index/$1";

This way, /15 will redirect to /post/index/15, but /bob will still load the Bob controller.



来源:https://stackoverflow.com/questions/7070500/codeigniter-routes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!