Question

I am using Codeigniter 1.7.2 and HMVC (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home).

I have these files and they are organized according to the HMVC:

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

In the routes.php, I have set up a route:

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

Everything works if the url is in this pattern: http://www.mydomain.com/index.php/welcome

But now I would like to remove the index.php from the url, so I created the .htaccess file:

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

Then I set the $config['index_page'] to empty:

$config['index_page'] = "";

Now I can access the page in this url pattern: http://www.mydomain.com/welcome

Although everything seems to work, I find that every time I access the page, it generates a 404 page not found error in the log:

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

This is not specific to the welcome page, all pages are having the same problem. I digged into the codes and discovered that this 404 Page Not Found message is generated from the MX_Router.php that comes with HMVC. Specifically, it's from this function:

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();
}

It's the show_404() function that gets called and therefore I am getting that error message. But since I can access every page without any problem using the url pattern which has index.php removed.

Why is HMVC thinking there's no controller found in this _validate_request() function? I will not get the 404 error message in the log if I revert the changes but this also means that I have to keep using the url pattern that has index.php, which looks pretty bad.

Anyone has encountered the same problem before? Many many thanks to you all.

Was it helpful?

Solution

I think the problem somehow relates to the favicon.ico, some web browsers automatically request yourdomain.com/favicon.ico and if there isn't one available, it generates a 404 error in the log.

OTHER TIPS

Maybe the error is in your .htaccess file. The official user guide actually has an example for this:

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

Does the problem still occur with this code in your .htaccess?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top