1
votes

I have my CakePHP router set up like this-

Router::connect('/*', array('controller' => 'posts', 'action' => 'p'));

This results in the dynamic url www.example.com/x22bh1 being routed to www.example.com/posts/p/x22bh1.

However my other urls that like www.example.com/aboutus or www.example.com/register etcetera are also routed to www.example.com/posts/p/* which is an unexpected behavior. Now to fix this I can define a regex based router. But for that to work, I'll need to specify all the exception pages that I don't want to get routed. So is there a way for both the features to work without specifying all the exception pages one by one in the router? Like if there is a controller and action for the URL then don't route but if there isn't then go to the default controller/action?

www.example.com/x22bh1 => Controller x22bh1 not found so route to www.example.com/posts/p/x22bh1.

www.example.com/register => Controller register with action index found so go to default page www.example.com/register/index

1

1 Answers

0
votes
Router::connect('/register',array('controller'=>'register','action'=>'index'));  
Router::connect('/aboutus',array('controller'=>'aboutus','action' =>'index')); 
# Blind rule  
Router::connect('/*', array('controller' => 'posts', 'action' => 'p'));

All other routes must be above this blind rule, otherwise all urls will be resolved in p action of posts controller. Means except defined routes all urls will be resolved in p action of posts controller and sequence will matter as I said earlier...