CodeIgniter throws error 404 when there is any problem with .htaccess file or main.php file.

Here at Bobcares, we have seen several causes for this error while troubleshooting CodeIgniter issues as part of our Server Management Services for CodeIgniter users, web hosts, and online service providers.

Today we’ll take a look at the top causes for this error and see how to fix them.


What causes CodeIgniter error 404 to occur

Before we get into the solution part let’s first discuss what causes this error to occur.

This error can happen for many reasons. Here are some of them.

1. First and foremost a main.php file can cause this error. Actually, this file must be present under the controllers’ folder and must have a class Main which extends CI_Controller as shown below.

class Main extends CI_Controller

2. Most commonly, the .htaccess file causes this error to occur. To check if there is an issue with the .htaccess file we access the below link.


If this link works then there can be any problem with .htaccess file.

For instance, the error appears as below.

CodeIgniter Error 404

How we fix CodeIgniter error 404?

Recently, one of our customers approached us with the same error message. Now, let’s see how our Support Engineers resolve this error for our customers.

Initially, we checked the .htaccess file and could find that the customer forgot to turn on the RewriteEngine. Also, he forgot to set RewriteBase. So we added the below code in the .htaccess file.

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

Then we added the below code in routes.php. This is because a default controller needs to be set in routes.php

$route['default_controller'] = 'blog';

Finally, this fixed the issue.

[Need any assistance to fix CodeIgniter errors? – We’ll help you]



In short, the CodeIgniter error 404 commonly occurs due to any issue with the .htaccess file or if the main.php file is not present under the controllers’ folder. Today, we saw how our Support Engineers fix this error for our customers.

The post CodeIgniter Error 404 – Tips to fix it! appeared first on Bobcares.