3

I'm using CodeIgniter with Nginx. I have just upgraded from CodeIgniter 2.2.6 to 3.1.4, following all the changelogs and upgrade instruction. Everything works perfectly 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 works and I'm able to load the other controllers.

Here is my 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 have also tried to comment all routes, but still the default one is ignored. Still, if I go http://francescoruvolo.it/Pages/show or either http://francescoruvolo.it/en, controllers are loaded just fine and it works. Many people had similar problems because they missed the part about enforcing the capitalized name for classes, but this is not the case as my controllers' name have been already 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 is properly forwarding all requests to index.php, in fact I don't need to specify it when loading controllers explicitly. Anyway, these lines are part of my Nginx configuration for the host:

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

What I don't get is that I'm actually able to get two different kind of 404 pages. For example, if I go to http://francescoruvolo.it/nonexistent.php Nginx correctly serves me a 404 page. At the same time, if I do not specify any path or explicitly specify index.php I get a 404 "well formatted", which means that the index.php from CodeIgniter has been actually run, but it failed to load the controller.

What am I missing? What else can I check?

3
  • stackoverflow.com/questions/12757211/… Commented May 29, 2017 at 12:55
  • @RobertRocha Thanks, but that doesn't solve my problem. He said he got a blank page, while I get a 404 page from CodeIgniter not from Nginx, which means that CodeIgniter is working properly. Commented May 29, 2017 at 13:05
  • Try with lower case in routes.php $route['default_controller'] = "pages/show"; Commented May 30, 2017 at 2:23

1 Answer 1

4

Solved. Apparently, I had an extra (unneeded) / at the end of my default route.

This was WRONG:

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

This is CORRECT:

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

Still, I don't quite get why. In fact, if I explicitly load the controller, it works even with the extra slash.

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

Sign up to request clarification or add additional context in comments.

2 Comments

"If anyone explains this, I'll gladly accept his answer. :)" They were very specific in docs: "Important: Do not use leading/trailing slashes." :) Also, according to the docs, default routes should stay on top.
@Tpojka This has to be something new in version 3.X, as I had that same route before upgrading and it has always worked flawlessly. Thanks for your input! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.