• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clean URLS and the Routes config file

[eluser]Steve Wanless[/eluser]
I have an application where I use the routes config;

$route[':any'] = "page/view/$1";

to achieve clean (and short) URLs to get something like this


instead of


Seeing this is the last line in my routes file, I have to manually enter a re routing line for every controller.
I would prefer to not have to enter something for each controller, otherwise they all get re routed to the pages controller.

Has anyone had this same problem? How did you deal with it?

Is it possible to extend the CI Routes file to go to a specific controller/method instead of the 404 page??


this seems to interest a lot of users, and i would be very glad to hear some experts opinion on how to achieve this...

i know how to route everything to a specific controller with the route[':any'] method, but would like to know what's the best way to do it when you only want some urls to go there.

what i mean is that i want something that does this:
1. if there is a controller that fits the name in the 'controller' segment of the url, go to it.
2. if there isn't, go to another, specified, controller. in this controller i can put the check for the slug and either show the right page, or show a 404.


Found it! Smile

CI2 now support $route['404_override'] in order to specify a controller\method that will be called when no existing controller\method is found.

Make sure to specify both the controller and the method, as the 'index' method will not be called automatically.


[eluser]Steve Wanless[/eluser]
Superb!! Fast, simple solution without having to hack the CI Core.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.