dqvj51875 2017-05-16 09:24
浏览 109
已采纳

Codeigniter URL在Web服务器上不起作用

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
  • 写回答

4条回答 默认 最新

  • dongtuo3795 2017-05-16 14:09
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动