Welcome Guest, Not a member yet? Register   Sign In
Clean URLS and the Routes config file
#1

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

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

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

example.com/about-us

instead of

example.com/page/view/about-us

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??

Thanks,
#2

[eluser]amosmos[/eluser]
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.

thanks,
amos
#3

[eluser]amosmos[/eluser]
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.

thanks,
amos
#4

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

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB