×


Fix CodeIgniter Error 404

When there is an issues with the main.php file or .htaccess file, a server error 404 will be triggered in a CodeIgniter Application.



Here at Ibmi Media, We have seen many support request from Customers in finding solutions to CodeIgniter issues such as this as part of our Web Development Services.
We will look into the main reasons why this error occurs and how to fix it in this context.

What triggers an error 404 in CodeIgniter?

In most cases, this error is as a result of issues in the main.php file. You have to edit this file which is located in the controller's Directory of the CodeIgniter application. Next, look into the "Main" class and ensure that it extends to "CI_Controller". It will be similar to;
class Main extends CI_Controller


In other cases, the .htaccess file can cause this problem to happen if we troubleshoot by accessing your website according to the following link as it applies to your case;
your_website.com/index.php/main/cek_login/


You will see that an error 404 is displayed.

Solution to CodeIgniter error 404

When you look into the .htaccess file, you have to check if the RewriteEngine is on. Setting the RewriteBase is also necessary. To fix this error, update the .htaccess file so that it looks like;
RewriteEngine on

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Finally, in the "routes.php" file, apply a default controller as follows;
$route['default_controller'] = 'home_page';


You will see that the issue has been fixed.

[Do you need help to fix CodeIgniter errors? We are here to support you.]


Conclusion

In summary, CodeIgniter server error 404 occurs when there is an issue in the .htaccess file or the "main.php" file located in the controller directory.


Conclusion

An #Error 404 is very common and we have seen our customers complain about it in their #CodeIgniter application website. This error means that there is a an incorrect configuration in the server files. Errors in the .htaccess file as well as the application routes.php file can cause this.