ZF2路由器无法进行分段

问题描述 投票:0回答:3

所以我有一个在本地运行的ZF2项目,效果很好。当我在登台服务器上设置它时遇到了路由问题。它将“/”路由到适当的控制器,但在访问时,说“/ blog”它将查找实际文件夹并返回以下错误:

The requested URL /blog was not found on this server.

通常,如果它与任何已定义的路由不匹配,ZF2将返回错误,指出URL无法与路由匹配。但似乎这打破了整个应用程序。有没有其他人遇到过类似的问题/发现修复?

谢谢。

apache zend-framework routing routes zend-framework2
3个回答
1
投票

尝试使用以下代码替换整个.htaccess文件。

this will work surely.

RewriteEngine On

RewriteCond%{REQUEST_FILENAME} -s [OR]

RewriteCond%{REQUEST_FILENAME} -l [OR]

RewriteCond%{REQUEST_FILENAME} -d

RewriteRule ^。* $ - [NC,L]

RewriteCond%{REQUEST_URI} :: $ 1 ^(/。+)(。+):: \ 2 $

RewriteRule ^(。*) - [E = BASE:%1]

RewriteRule ^(。*)$%{ENV:BASE} index.php [NC,L]

或者您可以访问此链接以获取更新详细信息。 Htaccess file for any project


1
投票

您的重写规则未被使用。如果您使用的是Apache,则表明您没有将.htaccess文件上传到登台服务器,或者您的登台服务器未配置为读取.htaccess文件。目前,请求甚至没有到达您的Zend Framework应用程序,因为您的Web服务器未配置为将其发送到那里。


0
投票

我真的不知道这是否可以解决你的疑问,但过去我和你几乎有同样的问题。这是我在module.config.php中使用的路由部分:

对于'admin'模块,例如:

<?php 
...
'router' => array(
        'routes' => array(
            'admin' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/admin',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Admin\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '[/:controller[/:action[/id/:id]]][/]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),

或者,对于主要模块:

<?php
'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            // The following is a route to simplify getting started creating
            // new controllers and actions without needing to create a new
            // module. Simply drop new controllers in, and you can access them
            // using the path /application/:controller/:action
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '[:controller[/:action[/id/:id]]][/]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
© www.soinside.com 2019 - 2024. All rights reserved.