I created a new entry in my .htaccess
file:
RewriteRule (.*).php(.*)$ index.php [NC,L]
Every request on a usual .php file is handled by index.php from ZF now.
Next I created an additional route to route those requests to a certain controller action:
$router->addRoute(
'legacy',
new Zend_Controller_Router_Route_Regex(
'(.+)\.php$',
array(
'module' => 'default',
'controller' => 'legacy',
'action' => 'index'
)
)
);
And this is the appropriate action:
public function indexAction() {
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->setLayout('full');
// Execute the script and catch its output
ob_start();
require($this->_request->get('DOCUMENT_ROOT') . $this->_request->getPathInfo());
$output = ob_get_contents();
ob_end_clean();
$doc = new DOMDocument();
// Load HTML document and suppress parser warnings
@$doc->loadHTML($output);
// Add keywords and description of the page to the view
$meta_elements = $doc->getElementsByTagName('meta');
foreach($meta_elements as $element) {
$name = $element->getAttribute('name');
if($name == 'keywords') {
$this->view->headMeta()->appendName('keywords', $element->getAttribute('content'));
}
elseif($name == 'description') {
$this->view->headMeta()->appendName('description', $element->getAttribute('content'));
}
}
// Set page title
$title_elements = $doc->getElementsByTagName('title');
foreach($title_elements as $element) {
$this->view->headTitle($element->textContent);
}
// Extract the content area of the old page
$element = $doc->getElementById('content');
// Render XML as string
$body = $doc->saveXML($element);
$response = $this->getResponse();
$response->setBody($body);
}
Very useful: http://www.chrisabernethy.com/zend-framework-legacy-scripts/