Zend Framework - how to rewrite URL for SEO url

I got a site on Zend Framework (im total noob in Zend). For example, I would like to make a single url " " so that it looks like " ". How do I achieve this in Zend? I'm new to Zend and Apache server. Where do I rewrite in Zend? I need a static url someebsite.com/page/about to rewrite to someebsite.com/about-product somewebsite.com/test/about


And the last question: where do I usually create rewrites? does it depend on the level / technology?


source to share

1 answer

In your bootstrap, you will need to set up some "routes". So if your bootstrap ends up something like this:

$frontController = Zend_Controller_Front::getInstance();


you can just add some route definitions like:

$frontController = Zend_Controller_Front::getInstance();

$router = $frontController->getRouter();
$router->addRoute( 'mylovelyroute',
    new Zend_Controller_Router_Route_Static( 'for-fun-link',
        array( 'controller' => 'test', 'action' => 'about' )
$router->addRoute( 'myotherroute',
    new Zend_Controller_Router_Route_Static( 'about-product',
        array( 'controller' => 'page', 'action' => 'about' )
$router->addRoute( 'justonemore',
    new Zend_Controller_Router_Route_Static( 'another/longer/path',
        array( 'controller' => 'mycontroller',
            'action' => 'myaction',
            'someparameter' => 'foo'



The first parameter addRoute()

is just a unique name. Zend_Controller_Router_Route_Static

takes the path you want to capture, then an array of parameters, including the controller and action (and module, if applicable).

If you want to add complexity, you can load routes from the database, or start using more dynamic routes. The docs here are a helpful next step: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard



All Articles