0

我正在使用 Codeigniter 1.7.2 和 HMVC(https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home)。

我有这些文件,它们是根据 HMVC 组织的:

system/application/modules/welcome/controllers/welcome.php
system/application/modules/welcome/views/index.php

在 中routes.php,我设置了一条路线:

routes['welcome']='welcome/index';

如果 url 采用这种模式,一切正常: http://www.mydomain.com/index.php/welcome

但现在我想从 url 中删除 index.php,所以我创建了 .htaccess 文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

然后我将其设置$config['index_page']为空:

$config['index_page'] = "";

现在我可以访问这个 url 模式的页面: http://www.mydomain.com/welcome

虽然看起来一切正常,但我发现每次访问该页面时,都会在日志中生成 404 page not found 错误:

DEBUG - 2011-01-02 08:28:52 --> URI Class Initialized
ERROR - 2011-01-02 08:28:52 --> 404 Page Not Found --> 

这不是特定于welcome页面的,所有页面都有相同的问题。我深入研究了代码,发现这条404 Page Not Found消息是由MX_Router.phpHMVC 附带的。具体来说,它来自这个函数:

public function _validate_request($segments) {      

    /* locate module controller */
    if ($located = $this->locate($segments)) return $located;

    /* use a default 404 controller */
    if (isset($this->routes['404']) AND $segments = explode('/', $this->routes['404'])) {
        if ($located = $this->locate($segments)) return $located;
    }   

    /* use a default 404_override controller CI 2.0 */
    if (isset($this->routes['404_override']) AND $segments = explode('/', $this->routes['404_override'])) {
        if ($located = $this->locate($segments)) return $located;
    }

    /* no controller found */
    show_404();
}

调用的是 show_404() 函数,因此我收到了该错误消息。index.php但是由于我可以使用已删除的 url 模式毫无问题地访问每个页面。

_validate_request()为什么 HMVC 认为在这个函数中没有找到控制器?如果我恢复更改,我不会在日志中收到 404 错误消息,但这也意味着我必须继续使用 url 模式index.php,这看起来很糟糕。

有人遇到过同样的问题吗?非常感谢你们。

4

2 回答 2

3

我认为这个问题与 favicon.ico 有关,一些网络浏览器会自动请求 yourdomain.com/favicon.ico,如果没有可用的,它会在日志中生成 404 错误。

于 2011-01-06T07:40:28.767 回答
0

也许错误在您的 .htaccess 文件中。官方用户指南实际上有一个例子:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

您的 .htaccess 中的此代码是否仍然存在问题?

于 2011-01-02T02:32:10.533 回答