CodeIgniter Forums
Routes are conflicting with each other. Is it possible to set priority? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Routes are conflicting with each other. Is it possible to set priority? (/showthread.php?tid=75259)



Routes are conflicting with each other. Is it possible to set priority? - desbest - 01-18-2020

Code:
$route['(:any)/(:any)/(:any)/(:any)'] = 'main/user/$1/$2/$3/$4';
$route['fetch/(:any)/(:num)/(:any)'] = 'fetch/$1/$2/$3';
$route['fetch/(:any)/(:any)/(:num)'] = 'fetch/$1/$2/$3';


Above is what I have in my routes.php

The route on the first line is making the below routes stop working. Any URL with fetch/apple/banana/123 will make the first line be followed instead of the third one.

Is it possible to set priority in routing, so if more than one rule is applicable, the rule that is above the other ones is what is used first?


RE: Routes are conflicting with each other. Is it possible to set priority? - jreklund - 01-18-2020

The priority are in what order you specify them. So place it in your priority order.

Code:
$route['fetch/(:any)/(:num)/(:any)'] = 'fetch/$1/$2/$3';
$route['fetch/(:any)/(:any)/(:num)'] = 'fetch/$1/$2/$3';
$route['(:any)/(:any)/(:any)/(:any)'] = 'main/user/$1/$2/$3/$4';