Zend框架2 https链接无法正常工作

时间:2014-08-01 17:30:49

标签: php zend-framework zend-framework2

网站链接

  1. http://test.scampaigns.com/Frontend/index
  2. https://test.scampaigns.com/Frontend/index
  3. 问题

    1号正在运行,2号表示404错误。

    问题在于HTTP网站运行正常。但只有HTTPS才能使用默认控制器,但其他控制器无法使用https:

    以下是我的module.config.php

    <?php
    
    return array(
        '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' => '/', //edited by koushik
                        '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][/:pId][/:devId]', //edited by koushik
                                'constraints' => array(
                                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                ),
                                'defaults' => array(
                                ),
                            ),
                        ),
                    ),
    
    
                ),
            ),
        ),
        'service_manager' => array(
            'abstract_factories' => array(
                'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
                'Zend\Log\LoggerAbstractServiceFactory',
            ),
            'aliases' => array(
                'translator' => 'MvcTranslator',
            ),
        ),
        'translator' => array(
            'locale' => 'en_US',
            'translation_file_patterns' => array(
                array(
                    'type' => 'gettext',
                    'base_dir' => __DIR__ . '/../language',
                    'pattern' => '%s.mo',
                ),
            ),
        ),
        'controllers' => array(
            'invokables' => array(
                'Application\Controller\Index' => 'Application\Controller\IndexController',
                'Application\Controller\Developer' => 'Application\Controller\DeveloperController', // edited by Poulami
                'Application\Controller\Template' => 'Application\Controller\TemplateController', // edited by Poulami
                'Application\Controller\Admin' => 'Application\Controller\AdminController',  
                'Application\Controller\Frontend' => 'Application\Controller\FrontendController',
                'Application\Controller\Ajaxcall' => 'Application\Controller\AjaxcallController'
            ),
        ),
    
        'view_manager' => array(
            'display_not_found_reason' => true,
            'display_exceptions' => true,
            'doctype' => 'HTML5',
            'not_found_template' => 'error/404',
            'exception_template' => 'error/index',
            'template_map' => array(
                'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
                'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
                'error/404' => __DIR__ . '/../view/error/404.phtml',
                'error/index' => __DIR__ . '/../view/error/index.phtml',
            ),
            'template_path_stack' => array(
                __DIR__ . '/../view',
            ),
        ),
         'translator' => array(
       'locale' => 'en_US',
          'translation_file_patterns' => array(
             array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
             ),
          ),
       ),// Added by Baishakhi
        // Placeholder for console routes
        'console' => array(
            'router' => array(
                'routes' => array(
                ),
            ),
        ),
    );
    

    有没有人可以帮助我并给我解决方案?

2 个答案:

答案 0 :(得分:0)

在尝试使用您的路由器配置查找RouteMatch时,使用什么url方案并不重要。

我认为您的问题位于您的apache配置中,因为您的https vhost不允许公用文件夹中包含.htaccess个文件。

当所有网址都失败且index.php正在运行时 - 这表示重写问题。检查您的apache配置,并且您的public文件夹可以使用选项

覆盖htaccess个文件

AllowOverride All

答案 1 :(得分:0)

如果您想在路线中使用https,则需要使用Zend\Mvc\Router\Http\Scheme路由器。您只需在路线配置中添加一个选项:'scheme' => 'https'

您可以按照以下简单示例:

'router' => array(
    'routes' => array(
        'name_route' => array(
            'type' => 'Scheme', //<-----add the type Schema here.
            'options' => array(
                'route' => '/url',
                'scheme' => 'https', //<-----specify this here.
                'defaults' => array(
                    //set the default options here.
                ),
            ),
        ),
        // ....
    ),
),

您还可以看到此post

希望这有帮助!