Antonello Pasella
Antonello Pasella

Reputation: 257

Zend_Controller_Router_Route issue

I need to trim the first part of my url

Example /param1/12234/module/controller/action would become /module/controller/action/param1/12234

I tried with

$router->addRoute('appid', new Zend_Controller_Router_Route('appid/:appid/:module/:controller/:action/', array(), array(2=> "module", 3=> "controller", 4=> "action")));

but won't works!

some helps?

Upvotes: 0

Views: 994

Answers (1)

OV Web Solutions
OV Web Solutions

Reputation: 825

Try:

<?php

   //-------------------------
   // Get router from front
   // controller
   $router = $this->frontController->getRouter();

   //-------------------------
   // Create route
   $route = new Zend_Controller_Router_Route(
      'controller/action/:appid/:param1',
      array(
         'module' => default',
         'controller' => 'index',
         'action' => 'index',
         'appid' => '',
         'param1' => 'default_value'
      ),

      //-------------------------
      // You can even add a regex
      // to parameters. Example,
      // appid can only be an integer
      array(
         'appid' => '\d+'
      )
   );

   //-------------------------
   // Add route to Router
   $router->addRoute('appid', $route);
?>

Of'course, you'll need to substitute a few things (module, controller, action and parameters). If you're not using modules, simply delete it from the array.

Finally, to use the route in the view, you can use:

$this->url(array('appid' => 1, 'param1' => 'custom_value'),'appid');

UPDATE:

You can try the following in your

<VirtualHost>

   RewriteEngine On
   RewriteRule ^/appid/(.*) /module/controller/action/$1 [R=301,L]
</VirtualHost>

If you don't need to use a permanent 301 redirect, you can drop the R

Upvotes: 1

Related Questions