当URI正确时获取404错误

时间:2013-02-24 04:37:20

标签: php zend-framework2 zend-studio zend-server

我使用的是PHP 5.4,Zend Studio和Zend-Server。

使用此uri时出现404错误:

http://localhost/MyExample/public/index.php

但是当我使用这个uri时,我会看到正确的页面显示:

http://localhost/MyExample/public/index.php/

我认为这两个uri都是一样的。

这是.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]

这是index.php代码:

<?php

/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();

1 个答案:

答案 0 :(得分:2)

注意:添加以前的评论作为答案

这是正确的行为。键入http://localhost/index.php时,传递给路由器的URI包含"index.php"

由于没有匹配"index.php"的路由,Zend Framework 2会显示404错误。

使用"/""/index.php/"the path matched by the router is empty时,您可以获得ZendSkeletonApplication匹配的默认"home"路由。