簡體   English   中英

ZF2路由器無法在暫存中使用

[英]ZF2 router not working on staging

因此,我有一個在本地運行的ZF2項目,並且效果很好。 當我在登台服務器上進行設置時,遇到了路由問題。 它將“ /”路由到適當的控制器,但是在訪問時說“ / blog”將查找實際文件夾並返回以下錯誤:

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

通常,如果它與任何已定義的路由都不匹配,則ZF2將返回錯誤,指出URL無法與路由匹配。 但這似乎是整個應用程序的突破。 是否還有其他人遇到類似問題/找到了解決方法?

謝謝。

您的重寫規則未使用。 如果您使用的是Apache,則可能沒有將.htaccess文件上傳到登台服務器,或者未將登台服務器配置為讀取.htaccess文件。 目前,請求甚至沒有到達您的Zend Framework應用程序,因為您的Web服務器未配置為將請求發送到該應用程序。

嘗試用以下代碼替換整個.htaccess文件。

這肯定會工作。

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文件

我真的不知道這是否可以解決您的疑問,但是過去我遇到的問題幾乎與您相同。 這是我在module.config.php中使用的路由部分:

對於“管理員”模塊,例如:

<?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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM