I am trying to route to a different action based on the url-extension in Cake2. I have this working route:
Router::connect(
'/:lang/:product/:version/:filename',
array(
'controller' => 'pages',
'action' => 'run',
'lang' => ':lang',
'product' => ':product',
'version' => ':version',
'filename' => ':filename'
),
array(
'pass' => array('filename'),
'lang' => '[a-zA-Z]{2}',
'product' => '[a-zA-Z0-9_!\-]+',
'version' => '[0-9]{3}',
'filename' => '[a-zA-Z0-9_!\-\.]+'
)
);
For the new route I simply added the extension and changed the action.
Router::connect(
'/:lang/:product/:version/:filename.json',
array(
'controller' => 'pages',
'action' => 'get',
'lang' => ':lang',
'product' => ':product',
'version' => ':version',
'filename' => ':filename'
),
array(
'pass' => array('filename'),
'lang' => '[a-zA-Z]{2}',
'product' => '[a-zA-Z0-9_!\-]+',
'version' => '[0-9]{3}',
'filename' => '[a-zA-Z0-9_!\-\.]+'
)
);
For some reason though the run action is still called (including the ext, so /../pages/json/run.ctp).
Thanks for your help!
hmm its probably because of the regexp on the first route
on the first rule you’re telling cake that
:filenamecan contain a point[a-zA-Z0-9_!\-\.]+So the router will always match the first rule..try changing the order of the routes, from specific to general
also check how cake manages the file extensions on routes
Hope this helps