Case Insensitive Routes In CakePHP 1.2RC3

Posted by Matt on Wed, Nov 12 2008

I wrote a post awhile back on how to do case insensitive routing in CakePHP. The method described there doesn't work anymore. The Cake Router now interprets the ":" character as the beginning of a named parameter.

An alternate way, which does work in RC3 is to begin your route with (?i), which will tell the regular expression engine to ignore the case for all characters to the right.

If you want to have an "about" page that is linked to by "/about”, "/About”, or "/aBoUt” you can use:

Router::connect(’/(?i)about’, array(’controller’ => ‘pages’, ‘action’ =>’display’, ‘about’));

I don't believe there is way to set this for all routes, but if there is I would love to hear it.

Posted in CakePHP

2 Comments

Ben said on Nov 13, 2008
Shouldn't this be a flag or a setting one would be able to set for the Router? It only makes sense that the routes should be case-insensitive. Such a flag should have existed a long time ago but with the option to enable case-sensitive routes.

Though, why would one prefer a case-sensitive approach is beyond me...
primeminister said on Nov 13, 2008
Very usefull!!! Thnx Matt