Code Igniter, Not Found 404 Error

7.8k Views Asked by At

I have a problem with my site. After upgrading to mySQL 5.6, then the host povider did a recompilation of Apache and PHP. apparently they also upgraded the WHM cPanel.

as for now my site can display properly, but when tried to login, it can't find the specific page requested.

The error Message:

The requested URL /main/cek_login was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

error messages from cPanel:

[Mon Dec 22 10:10:58 2014] [error] File does not exist: /home/xxx/public_html/main [Mon Dec 22 10:10:56 2014] [error] File does not exist: /home/xxx/public_html/404.shtml

My analyses so far:

CI version : 2.2
PHP Version : 5.4.3.5
mySQL version : 5.6.21
cPanel Version 11.46.1 (build 4)

main -> is actually a file called main.php
cek_login -> is a function inside main.php that run verification against record in user table.

the folder structure as follows.

/home
   /application
       /controllers
           /main
       /view
          /login_view
   /system
   /assets
   /cgi-bin 

The code as follows

<div class="loginForm">
  <?=($_GET[ 'error'])? "<div class='alert'>$_GET[error]</div>": ""?>
    <form class="form-horizontal" action="<?php echo base_url().'main/cek_login'; ?>" method="POST">

config.php inside application folder
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; -> tried AUTO before, but useless. Previously was AUTO

.htaccess in root folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

.htaccess in another folder
deny from all

routes.php
$route['default_controller'] = "main";
$route['404_override'] = 'not_found';

I tried to see config files as well and tried a lot of tricks before posting this.

my suspicion is on the base_url function or the routing mechanism. I am not sure.

I am NEW to Code Igniter or PHP, also in Server Administration. my strength lies in Database.

Please help on narrowing the root problem.

best regards, Ridwan

3

There are 3 best solutions below

1
On BEST ANSWER

That error can happen for many reason. here is some
1.make sure you have main.php under controllers folder and inside main.php you should have a class Main which extends CI_Controller like this

class Main extends CI_Controller

2.make sure your .htaccess working.If your previous step is ok then try to hit this link

your_site_url/index.php/main/cek_login//make sure cek_login function exists inside the controller

If this link works you may have .htaccess problem
3.your cpanel error tells that your .htaccess not working.
check your server if it has main .htaccess which is redirecting your site if file not found.If so then your sub .htaccess will not work.
I think this is the main reason that produce your error.

1
On

Please check your config.php

$config['base_url']

then check 'routes.php', add the line below

$route['main/(:any)'] = 'main/index';

Then, add your login check in your controller file.

// Login check
    $exception_uris = array(
            'main/cek_login',
            'main/cek_logout'
    );
    if (in_array(uri_string(), $exception_uris) == FALSE) {
        if ($this->user_m->loggedin() == FALSE) {
            redirect('main/cek_login');
        }
    }
0
On

Just upload a test file and check document root of your server directory.

1.Create a file info.php 2. Write code

<?php
 phpinfo();

3.Open any broswer and type http://www.yourdomain.com/info.php

  1. If it works fine, find document roon in listed information of info.php page

  2. If this http://www.yourdomain.com/info.php not works, contact your server support team to fix it. Basically problem with server configuration, not with Codeigniter files.