CodeIgniter Forums
Custom routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Custom routes (/showthread.php?tid=73724)



Custom routes - bastian - 05-27-2019

Hi there

Maybe someone can give me an advice in setting custom routes. What I'd like to achieve is the following:

Theres a controller called Blog.php

I want some URI to get directed to this controller, e.g.:

/place/info/files
/place/info/people

There's no controller Place. Instead Blog should be used but with the segments provided. I need to have the URI segments to be available in Blog.php.

Hm, I hope I was clear enough in what I am working on…

Thanks for any advice.


RE: Custom routes - Wouter60 - 05-27-2019

PHP Code:
$route['place/(:any)'] = 'blog/$1'



RE: Custom routes - bastian - 05-27-2019

Thanks for your idea. I tried it and it works for URIs with a second segment. But if there are more than two segments, it doesn't work anymore…


RE: Custom routes - milengardev1994 - 09-01-2019

You can try something like this:

Code:
$route['login/(.+)'] = 'auth/login/$1';




This is will capture all segments after 'login'. 
I would be a bit hesitant to use it since if you have route that starts with the '/login' it will be overwritten. 

So the following construction will be automatically redirected to 'auth/login/$1'


Code:
$route['login/app] = 'auth/app/$1';



RE: Custom routes - InsiteFX - 09-02-2019

Any route that contains (:any) or (.+) should be the very last route.

This is because they are a catch all route, so place them after all other routes.

Then you will not over write or have problems with your routing.


RE: Custom routes - ehabafia - 09-02-2019

(05-27-2019, 01:07 PM)bastian Wrote: Thanks for your idea. I tried it and it works for URIs with a second segment. But if there are more than two segments, it doesn't work anymore…

If I understand it well, I think you should try:

PHP Code:
$route['place/info/(:any)'] = 'blog/$1'