codeigniter routes

2019-06-10 09:04发布

问题:

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.