CodeIgniter Forums
wildcard routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: wildcard routes (/thread-27293.html)



wildcard routes - El Forum - 02-06-2010

[eluser]richzilla[/eluser]
Hi all, I've looked through the user guide, but it doesn't seem to make what i want to do very clear, or I'm missing something...

Basically i want to route a url with any function name to the same controller, but with the function name appended to the end. so for example in my site:

id want
Code:
/health-and-safety/courses
to route to
Code:
/hs/courses
and also
Code:
health-and-safety/home
to route to
Code:
hs/home

I can do it on the routes side of the statement with
Code:
/health-and-safety/:any
as the value for the route but how to i get the
Code:
:any
value to be copied onto the hs/ side?

Any help would be appreciated.
Thanks


wildcard routes - El Forum - 02-06-2010

[eluser]Kosonome[/eluser]
You change the route /health-and-safety/home -> /hs/index/home, then you can make one more route /hs/index/home -> /hs/home.

Or you can make a regular expression. I guess that's the best way, since it gives me headaches (I'm not good with them yet Sad ).


wildcard routes - El Forum - 02-06-2010

[eluser]richzilla[/eluser]
Thanks for the help. Yea, i thought about doing that, but the health and safety section might have 20 pages eventually, so im trying to avoid hard coding routes for every page, what i want is for it to basically replace the
Code:
health-and-safety/
part with
Code:
hs/



wildcard routes - El Forum - 02-07-2010

[eluser]tomcode[/eluser]
Put these two lines in Your config/routes.php :

Code:
$route['health-and-safety'] = 'hs';
$route['health-and-safety/(:any)'] = 'hs/$1';

Now all requests for health-and-safety end in the controller hs.