2013-07-12 46 views
0

我想運行沒有.htaccess的應用程序,並且我刪除了它。現在,當我點擊n個主頁時'localhost/testsite/index.php /'它的工作原理和相關的鏈接網址也正常工作。但是當我嘗試打開'localhost/testsite/index.php'時,它會給出下面的錯誤消息。在zend 2.2中刪除htaccess後Zend框架主頁的URL索引問題

發生404錯誤 找不到頁面。 請求的URL無法通過路由進行匹配。

而且當我打開的「localhost /測試網站/」的主頁來正常,但相關鏈接停止工作異常。我的應用程序module.config.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' => '/application', 
       'defaults' => array(
        '__NAMESPACE__' => 'Application\Controller', 
        'controller' => 'Index', 
        'action'  => 'index', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'default' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/[:controller[/:action]]', 
         'constraints' => array(
          'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
          'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
         ), 
         'defaults' => array(
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 
'controllers' => array(
    'invokables' => array(
     'Application\Controller\Index' => 'Application\Controller\IndexController' 
    ), 
), 
'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', 
    ), 
), 

);

如果有人在zend 2.2中運行沒有htaccess的應用程序,請幫忙。

回答

1

您可以添加一個通用的路線,使斜線可選的,你可以用網段路由型

/** 
* Generic Route 
*/ 
'generic' => array(
    'type' => 'segment', 
    'options' => array(
     'route' => '[/:controller[/:action[/:id]]][/]', // allow trailing slash too [/] 
     'constraints' => array(
      '__NAMESPACE__' => 'Application\Controller', 
      'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
      'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
      'id'   => '[0-9]+', 
     ), 
     'defaults' => array(
      'controller' => 'Index', 
      'action'  => 'index', 
     ), 
    ), 
), 
+0

我已經把index.php,js,img和css放在應用程序的根文件夾中。應用程序已經託管在IIS上,我們沒有使用htaccess。應用程序使用localhost/testsite/index.php /,localhost/testsite /而不是localhost/testsite/index.php運行。請幫忙。 – vikashkt

0

您ZF2應用程序的起點設在公共/ index.php文件是無法做到這一點在發佈主機的根文件夾中,所以我們需要.htaccess(使用apache的mod_rewrite)將所有瀏覽器請求重定向到[public/index.php],如果您有任何其他機制來模擬重定向,您可以繞過.htaccess文件。