Redirect url to custom url using .htaccess or bootstrap in ZF1

255 Views Asked by At

I'm working with Zend Framework 1.9 and facing some problems with the routes. Actually, looking for a way to route url to custom one (url), but unfortunately couldn't find a solution after surfing on internet as well as on Stack Overflow.

Well, the problem is that the defined url is working fine: http://example.com/user/detail/code/hsg45464

but, I want to change the above url to custom url, something like this: http://example.com/[user_name]/[course]/[cource_description]

So, is there any possibility to achieve this custom url in Zend Framework 1.9 (.htaccess or bootstrap).

Cheers!

1

There are 1 best solutions below

0
Adeel On

I would prefer to do it in Bootstrap.php instead of changing anything in config, index.php or .htaccess

## /application/Bootstrap.php ##

protected function _initRoutes()
{
    $frontController = Zend_Controller_Front::getInstance();
    $router = $frontController->getRouter();

    $router->addRoute('user-course', new Zend_Controller_Router_Route('/:username/:course/:desc', array(
        'controller' => 'default_controller_name',
        'action' => 'default_action_name'
    )));
}

After that you need to create a controller and a view to render it.

Also, you can go through the routing documentation of Zend Framework 1.9 in detail, so here is the link: Zend Framework 1.9 Routing