简体   繁体   English

PHP-Zend_Controller_Router_Route_Regex不起作用

[英]php - Zend_Controller_Router_Route_Regex not working

I wanna match an url like this http://localhost/sunnetwap/1-hot and rewrite into this http://localhost/sunnetwap/?c=1&s=hot . 我想匹配一个http://localhost/sunnetwap/1-hot这样的URL,然后重写为http://localhost/sunnetwap/?c=1&s=hot In my Bootstrap and and _initRoutes function i wrote: 在我的Bootstrap和_initRoutes函数中,我写道:

        $frontController = Zend_Controller_Front::getInstance();
        $route = new Zend_Controller_Router_Route_Regex(
                "([0-9]*)-([a-z]*)", 
                array(
                    'module' => 'default',
                    'controller' => 'index',
                    'action' => 'index'
                ),
                array(
                    1 => 'c',
                    2 => 's'
                ));
        $frontController->getRouter()->addRoute('home',$route);

but it doesn't work. 但这不起作用。 Can you help me? 你能帮助我吗?

The issue is probably related to the base url of your app. 该问题可能与您应用的基本网址有关。

It is possible that you have deployed your app at the base url http://localhost/ . 您可能已将应用程序部署在基本URL http://localhost/ In this case, your routes would need to include the sunnetwap portion. 在这种情况下,您的路线将需要包括sunnetwap部分。

But I'm guessing that your app is deployed to http://localhost/sunnetwap/ . 但是我猜测您的应用程序已部署到http://localhost/sunnetwap/ In that case, your route is fine, but it's likely that you either have a sunnetwap alias on localhost or that the whole app is dropped into into your <docroot>/sunnetapp and that you have moved contents of the public folder up a level with corresponding changes to .htaccess . 在这种情况下,你的路线是好的,但很可能是你要么有一个sunnetwap的别名localhost或整个应用程序被放入到您的<docroot>/sunnetapp并且您已经移动内容的public文件夹了一个级别.htaccess相应更改。 Both of these will potentially have impact on the routing. 两者都可能对路由产生影响。

See this answer for some ideas on how to deploy to a sub-directory when you can't map a virtual host to your app. 有关无法将虚拟主机映射到应用程序时如何部署到子目录的一些想法,请参见此答案

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

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