【问题标题】:Getting 404 Error when the URI is rightURI 正确时出现 404 错误
【发布时间】:2013-02-24 04:37:19
【问题描述】:

我正在使用 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();

【问题讨论】:

  • 与 .htaccess 有什么关系?
  • 有可能。我只是不确定是什么。
  • 您能否发布您拥有的 .htaccess 相关代码或与 url 相关的任何其他内容,例如:php 代码
  • 我添加了 .htaccess 文件和 php.index 的 php 代码
  • 在我看来似乎是正确的。没有匹配index.php 的路由,所以会抛出 404。使用//index.php/时,路由器匹配的路径是空的,所以得到home路由匹配。

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


【解决方案1】:

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

这是正确的行为。输入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"路由匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-17
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多