CodeIgniter does not load default controller in '/'

I am using CodeIgniter with Nginx. I just upgraded from CodeIgniter 2.2.6 to 3.1.4 following all change instructions and upgrade instructions. Everything works fine, but the default controller i.e. http://francescoruvolo.it (or even http://francescoruvolo.it/index.php ) shows a 404 page, but all other routing rules are working and I can load other controllers.

Here is mine routes.php

:

$route['(it|en)/contact/check_form'] = "Email/validate_form/$1";
$route['(it|en)/contact'] = "Email/show_form/$1";
$route['(it|en)/(:any)'] = "Pages/show/$1/$2";
$route['(it|en)'] = "Pages/show/$1";
$route['default_controller'] = "Pages/show/";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

      

I also tried to comment out all routes, but ignored by default. However, if I go to http://francescoruvolo.it/Pages/show or http://francescoruvolo.it/en the controllers load just fine and it works. A lot of people have had similar problems because they missed the part about using capitalized names for classes, but this is not the case since my controller name has already been fixed.

These are the parameters in config.php

:

$config['base_url'] = 'http://francescoruvolo.it/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

      

And Nginx looks like it redirects all requests to correctly index.php

, in fact I don't need to specify it when explicitly loading controllers. Anyway, these lines are part of my Nginx configuration for the host:

location / {
    try_files $uri $uri/ /index.php;
}

      

What I don't understand is that I can actually get two different types of 404 pages. For example, if I go to http://francescoruvolo.it/nonexistent.php , then Nginx will correctly serve me a 404 page. At the same time, if I don't specify any path or explicitly specify it index.php

, I get a "well-formatted" 404, which means that index.php from CodeIgniter is actually running, but it was unable to load the controller.

What am I missing? What else can I check?

+3


source to share


1 answer


solvable. Apparently I had an extra (unnecessary) one /

at the end of my default route.

It was WRONG:

$route['default_controller'] = "Pages/show/";

      

It is right:



$route['default_controller'] = "Pages/show";

      

However, I don't quite understand why. In fact, if I load the controller explicitly, it works even with an extra forward slash.

If anyone explains this, I would gladly accept his answer. :)

+4


source







All Articles