1

I was developing in XAMPP environment on my local machine, and everything is fine. I can access my controller like this:

localhost/myproject/index.php/catalog/home/get

catalog is the sub folder under controllers.

However, after I uploaded my project to the server. I should be able to access my page by the following url:

http://www.example.com/index.php/catalog/home/index

but this gives me a 404 page.

The only url works is the default page I defined in the route.php file:

$route['default_controller'] = 'welcome';

In the config.php, I set my base_url to be http://www.example.com/

All my controllers' first letter are capitalized and I'm using CI 3.1X. My server is a linux which uses nginx instead of apache. I tried to modify or delete my .htaccess file, but it doesn't solve my problem.

I'm not looking for an exact answer, I would like to know how to debug my code in this situation.

Here is an example of one of my controllers:

<?php

class Survey extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('catalog/model_survey');
        $this->load->helper('url');
    }

    public function index()
    {
        $error = $this->input->get('error');

        if (isset($error)) {
            $data['error'] = true;
        } else {
            $data['error'] = false;
        }

        $data['action'] = "index.php/catalog/success";
        $data['base'] = base_url();

        $this->load->view('catalog/survey', $data);
    }
}

Here is my folder structure:

application
|-- cache
|-- config
|-- controllers
|   |-- admin
|   |   |-- common
|   |   |-- redpacket
|   |   |-- setting
|   |   `-- tools
|   `-- catalog
|-- core
|-- helpers
|-- hooks
|-- language
|   |-- chinese
|   |   `-- admin
|   |       |-- common
|   |       |-- redpacket
|   |       |-- setting
|   |       `-- tools
|   `-- english
|       `-- admin
|           `-- common
|-- libraries
|-- logs
|-- models
|   |-- admin
|   |   |-- common
|   |   |-- redpacket
|   |   |-- setting
|   |   |-- tools
|   |   `-- user
|   `-- catalog
|-- third_party
`-- views
|-- admin
    |   |-- common
    |   |-- redpacket
    |   |-- setting
    |   `-- tools
    |-- catalog
    `-- errors
|-- cli
        `-- html
26
  • Have you used .htaccess file? Commented May 16, 2017 at 9:27
  • @NaimMalek Yes, by default there was a .htaccess file in the CI project folder. I tried to delete it, but the problem is still there Commented May 16, 2017 at 9:29
  • 1
    Please check filenames, you need to upload filename with First Letter Capital. e.g. Home.php Commented May 16, 2017 at 9:29
  • @kishor10d My file names are good, I read your suggestion in many other posts. I don't think this is the reason in my case Commented May 16, 2017 at 9:31
  • It might be permission issue check your catalog folder's permission. @SSD Commented May 16, 2017 at 9:34

5 Answers 5

2

it looks like you forgot to update .htaccess file on the server

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

2 Comments

could you provide more information? how do I update it? this is what it looks like <IfModule authz_core_module> Require all denied </IfModule> <IfModule !authz_core_module> Deny from all </IfModule>
You need to look for htaccess used on your machine and install the same one on the server. Also check apache logs for 404 errors. It can show you actual reason of this error. Thanks.
2

Consider the following checklist.

  1. Check Controller file name Survey.php, S must be capital.
  2. Check folder name catalog for case sensitivity.
  3. Same for view and models.

I use following .htaccess code in most of my projects.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

Edited answer:

In your given directory hierarchy, all your controller and model names are in lower case. As per the CI 3.X standard, the Classes first character is capitalized and the same is applicable for their respective files.

3 Comments

just tried your .htaccess code, doesn't work in my case
@SSD Could you please post your directory & file hierarchical structure screen shot.
@SSD I can see your catalog directory is empty, no controller is available. Again, you have posted Survey.php controller code, there is no file in the directory hierarchy you have posted. Please confirm.
1

localhost/myproject/index.php/catalog/home/get

Here localhost is hostname, myproject is project name catalog is controller sub folder name, home is controller name, and get is function under home controller.

in Home make H capital as it is class name, and check .htaccess file

Comments

1

After comparing my local environment and the production environment, I found that I'm using Apache on my local machine, but nginx on the server. Thus, I'm guessing the problem would be the setting of my nginx config file.

After doing some research, this is what I found online: https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/?highlight=codeigniter

I modified my nginx config file to this, and everything works fine now. By using this config, it also get rid of the index.php in the url. You can access the web by type http://www.example.com/survey, or if you did what I did, adding a sub folder under controller, just simply add your sub folder in the url http://www.example.com/catalog/survey

Comments

0

Credit to kishor10d in the comments. I wanted to highlight this as a possible solution:

If you are developing on a windows machine and deploying to a linux web server, the capitalization of the files is critical. Windows ignores case sensitivity and Linux requires a match. The fix for me was to capitalize the controller's filename.

Comments

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.