Let's assume you have a structure like foobar/test/123
where foobar
is your CMS page identifier. By default, Magento will try to match that whole string to a CMS page identifier and when it fails you will be presented with a 404 page. You can go around that by modifying match
method found in Mage_Cms_Controller_Router
class.
First extract CMS page identifier:
$params = explode('/', $identifier);
$identifier = $params[0];
If the match is found we iterate over passed parameters and set them on request object
for ($i = 1, $l = sizeof($params); $i < $l; $i += 2) {
$request->setParam($params[$i], isset($params[$i+1]) ? urldecode($params[$i+1]) : '');
}
Putting it all together:
public function match(Zend_Controller_Request_Http $request)
{
if (!Mage::isInstalled()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
exit;
}
$identifier = trim($request->getPathInfo(), '/');
$condition = new Varien_Object(array(
'identifier' => $identifier,
'continue' => true
));
Mage::dispatchEvent('cms_controller_router_match_before', array(
'router' => $this,
'condition' => $condition
));
$identifier = $condition->getIdentifier();
if ($condition->getRedirectUrl()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect($condition->getRedirectUrl())
->sendResponse();
$request->setDispatched(true);
return true;
}
if (!$condition->getContinue()) {
return false;
}
# extract page identifier
$params = explode('/', $identifier);
$identifier = $params[0];
$page = Mage::getModel('cms/page');
$pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId());
if (!$pageId) {
return false;
}
# set params on request object
for ($i = 1, $l = sizeof($params); $i < $l; $i += 2) {
$request->setParam($params[$i], isset($params[$i+1]) ? urldecode($params[$i+1]) : '');
}
$request->setModuleName('cms')
->setControllerName('page')
->setActionName('view')
->setParam('page_id', $pageId);
$request->setAlias(
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
$identifier
);
return true;
}