Codeigniter返回404页面未找到

时间:2022-10-09 21:32:01

I'm developing web application using Codeigniter. 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.

我正在使用Codeigniter开发Web应用程序。到目前为止,我已经设法在我的localhost上运行该应用程序。但是当我将内容上传到网络托管服务器时,我无法让它运行。

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.
  2. 奇怪的是,我可以调用控制器Welcome.php,它是codeigniter的样本控制器,并且显示良好。

  3. But I can't call any other controller which my default controller eventhough I have set it in routes.php, config.php etc.
  4. 但我不能调用我的默认控制器的任何其他控制器,尽管我已经在routes.php,config.php等中设置了它。

Below is my configuration for these files:

以下是我对这些文件的配置:

routes.php

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

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

<?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.

谢谢大家,希望我的解释清楚。

1 个解决方案

#1


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

Or here:

/etc/php/php.ini

/etc/php5/php.ini

Find the line with disable_functions, one of them likely being phpinfo. You'll need to remove phpinfo from the list of disabled functions in disabled_functions=

找到带disable_functions的行,其中一行可能是phpinfo。您需要从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

#1


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

Or here:

/etc/php/php.ini

/etc/php5/php.ini

Find the line with disable_functions, one of them likely being phpinfo. You'll need to remove phpinfo from the list of disabled functions in disabled_functions=

找到带disable_functions的行,其中一行可能是phpinfo。您需要从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