Hi, I understand that by default Zend Framework uses a route definition of :module/:controller/:action. As a result, if I have a domain called http://domain.com, the following urls will dispatch to the indexAction of the IndexController of the default module:
http://domain.com/default/index/index http://domain.com/default/index http://domain.com/index/index http://domain.com/index http://domain.com I really did not want users to be able to type any of the above urls to gain access to IndexController::indexAction(). Instead, I wanted users to type only the following to access IndexController::indexAction(): http://domain.com http://domain.com/index http://domain.com/index.html Here is how I did it: 1. I added a static route to the front controller to route http://domain.com/index.html to IndexController::indexAction(): $router = $front->getRouter(); $route = new Zend_Controller_Router_Route_Static( 'index.html', array( 'controller' => 'index', 'action' => 'index', 'module' => 'default' ) ); $router->addRoute('home', $route); 2. I created an error.phtml view script for the IndexController (app/view/scripts/index/error.phtml): <h1>An error occurred</h1> <h2><?= $this->message ?></h2> 3. In my indexAction(), I check the REQUEST_URI and take the user to the error.phtml view script if the REQUEST_URI does not match any of the desired REQUEST_URI: public function indexAction() { $requestUri = explode("?", $this->_request->getRequestUri()); if ($requestUri[0] != '/' && $requestUri[0] != '/index' && $requestUri[0] != '/index.html') { $this->_response->setHttpResponseCode(404); $this->view->message = 'Page not found'; $this->_helper->viewRenderer->render('error'); } } -- View this message in context: http://www.nabble.com/Zend-Router-Route-dilemma-and-solution-tp22282054p22282054.html Sent from the Zend Framework mailing list archive at Nabble.com.
