简体   繁体   English

找不到Codeigniter返回404页面

[英]Codeigniter return 404 page not found

I'm developing web application using Codeigniter . 我正在使用Codeigniter开发Web应用程序。 So far I have managed to run the application on my localhost. 到目前为止,我已经设法在本地主机上运行该应用程序。 But when I upload the content unto the web hosting, I can't get it to run. 但是,当我将内容上传到虚拟主机时,我无法运行它。

This is what I've tested so far: 到目前为止,这是我测试过的内容:

  1. strangely, I can call the controller Welcome.php which is the sample controller from codeigniter, and showing well. 奇怪的是,我可以调用控制器Welcome.php ,它是来自codeigniter的示例控制器,并且显示得很好。
  2. But I can't call any other controller which my default controller eventhough I have set it in routes.php, config.php etc. 但是,即使我在routes.php,config.php等中设置了其他控制器,也无法将其称为默认控制器。

Below is my configuration for these files: 以下是这些文件的配置:

routes.php routes.php

$route['default_controller'] = 'lokadok';
$route['404_override'] = '';
$route['upload/do_upload'] = 'upload/do_upload';

config.php config.php

$config['base_url'] = (( isset($_SERVER['HTTP_HOST']) && strlen($_SERVER['HTTP_HOST'])>0) ?
                    'http://' . $_SERVER['HTTP_HOST'] : 'http://www.lokadok.co.id' );
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '.html';
$config['charset'] = 'UTF-8';

and this is the .htaccess 这是.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)\.html$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

My default controller is this: 我的默认控制器是这样的:

lokadok.php lokadok.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Lokadok extends CI_Controller {

    public function index() {
        $data['is_login'] = $this->session->userdata(LOGGED_IN);            

        $specialty = $this->input->post('specialty', '');
        $address = $this->input->post('address', '');
        $doc_name = $this->input->post('doc_name', '');

        if ($specialty == '' && $address == '' && $doc_name == '') {
            $this->load->model('model_share');

            $data['custom_css'] = array(
                'style/custom/lokadok.css'
            );

            $data['sort_by'] = 1;
            $data['pop_specialties'] = $this->model_share->get_specialties(true);
            $data['specialties'] = $this->model_share->get_specialties();

            $this->load->view('templates/header', $data);
            $this->load->view('lokadok_view');
            $this->load->view('templates/footer', $data);
        } else {    
            redirect("search?specialty=$specialty&address=$address&doc_name=$doc_name&sort_by=1");
        }       
    }
}
?>

I have been looking for the answer for awhile and still couldn't figure it out. 我一直在寻找答案,但仍然无法弄清楚。 So if anyone can spot the error, I would really appreciate it. 因此,如果任何人都能发现错误,我将非常感激。

To check on the location site you can go to: www.lokadok.co.id which I expect to call my default controller. 要检查定位站点,您可以转到:www.lokadok.co.id,我希望将其称为默认控制器。

and try to call http://www.lokadok.co.id/welcome which is strangely running well. 并尝试致电http://www.lokadok.co.id/welcome ,它运行正常。

Thank you all, and hope my explanation is clear. 谢谢大家,希望我的解释清楚。

I think the answer lies within your question : 我认为答案在于您的问题:

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

I think you need to enable mod_rewrite 我认为您需要启用mod_rewrite

UPDATED 更新

Find your php.ini in 在以下位置找到您的php.ini

/etc/php.ini /etc/php.ini

Or here: 或在这里:

/etc/php/php.ini /etc/php/php.ini

/etc/php5/php.ini /etc/php5/php.ini

Find the line with disable_functions, one of them likely being phpinfo. 用disable_functions查找行,其中之一可能是phpinfo。 You'll need to remove phpinfo from the list of disabled functions in disabled_functions= 您需要从disabled_functions =中的禁用功能列表中删除phpinfo

IF UBUNTU THEN 如果UBUNTU然后

To enable the rewrite module, run "apache2 enable module rewrite" in terminal: 要启用重写模块,请在终端中运行“ apache2 enable module rewrite”:

sudo a2enmod rewrite

You need to restart the webserver to apply the changes: 您需要重新启动Web服务器以应用更改:

sudo service apache2 restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM