【问题标题】:url not found in zend framework though working for index page虽然适用于索引页面,但在 zend 框架中找不到 url
【发布时间】:2012-02-08 22:36:50
【问题描述】:

我正在尝试使用 zend 框架开发网站,所以我创建了一个 index.php 文件,我的所有请求都在其中创建并创建了两个控制器,一个是 IndexController,另一个是 TestController

Class IndexController extends Zend_Controller_Action{
    public function indexAction(){
        echo "Index Index Jamla";
    }
    public function displayAction(){
        echo "Index Display Jamla";
    }
}

现在当我访问 url http://test/ 它正确调用 IndexController 及其 IndexAction 函数 但是当我访问网址http://test/index/index 它显示消息 url /index/index is not found on this server 与我访问 http://test/test/index 时相同。

虽然http://test/ 等价于http://test/index/index

【问题讨论】:

  • 我删除了netbeans 标签,因为它与问题没有任何共同之处

标签: zend-framework


【解决方案1】:

Zend 框架的重写规则不起作用。

http://test 有效,因为 Apache 默认运行 index.php,它将运行您的应用程序。路由器将看不到 URL 参数,因此它路由到索引控制器索引操作。当您尝试访问其他任何内容时,Apache 正在处理请求并且不会将其重写为 index.php,因此您会收到 404 not found。

确保包含重写规则的 .htaccess 在您的公用文件夹中。通过在 httpd.conf 和/或 httpd-vhosts.conf 中设置 AllowOverride All 来检查 Apache 是否允许处理文档根目录的 .htaccess 文件。

【讨论】:

  • 还要确保在 apache.conf 中启用了 mod rewrite。我几乎在每次新安装时都忘记了这一点!
【解决方案2】:

傻但你能再检查一次 index.phtml 文件是否存在于views/scripts/index/下

【讨论】:

    【解决方案3】:

    确保您在 Apache 配置中将 AllowOverride 设置为 All 并启用了 mod_rewrite 扩展

    【讨论】:

      猜你喜欢
      • 2012-09-18
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多