简体   繁体   English

Zend_Controller_Router_Route问题

[英]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 示例/param1/12234/module/controller/action将变为/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"))); $ 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? 有帮助吗?

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 如果您不需要使用永久性301重定向,则可以删除R

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM