CodeIgniter Forums
route any to a controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: route any to a controller (/showthread.php?tid=52413)



route any to a controller - El Forum - 06-09-2012

[eluser]Unknown[/eluser]
Hi everyone,

I'm trying to make a route to get that :

any/thing/etc to site/any/thing/etc ( where site is a controller from a HMVC module )

I tried some stuff like :

Code:
$route[':any'] = "site/$1";

I can't get that working... and i can't do that using a htaccess, need to do that inside CI

Anybody can help me ?

Thanks a lot




route any to a controller - El Forum - 06-09-2012

[eluser]bralens[/eluser]
not an expert but shouldn't it be something like
Code:
$route['(:any)'] = "site/$1";
?


route any to a controller - El Forum - 06-09-2012

[eluser]Unknown[/eluser]
Yes it works thank you.

It didn't work because it's overriden by the default controller.

Example : if i write :

Code:
$route['default_controller'] = "welcome";
$route['(:any)'] = "site/$1";

example.com/ displays the welcome controller but example.com/method displays site/method (good).

So i had to define $route['default_controller']="site" too and it works.


route any to a controller - El Forum - 06-09-2012

[eluser]InsiteFX[/eluser]
Code:
/* ------------------------------------------------------------------------
* DO NOT! REMOVE THIS LINE: This needs to be the very last route in the file.
* ------------------------------------------------------------------------
*/
$route['(.*)'] = 'site/$1';

This can also be used with _remap