CodeIgniter "The page you requested was not found." error?

CodeIgniter "The page you requested was not found." error?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

CodeIgniter "The page you requested was not found." error?

When you hit a 404 Not Found in an older version of CodeIgniter, the instinct is often to check your routing configuration immediately. However, the error usually stems from a mismatch between what your routes file promises and what your controller actually returns when that promise isn't kept.

Looking at the provided routes.php, we see a classic pattern for numeric routing: $route['(:num)'] = "page/index/$1";. This tells the router to pass any number captured in the URL to the Index method of the Page controller. The logic seems sound on paper, but the failure point lies inside the index() method itself.

The controller code attempts to load an image based on the ID provided in the URL: $image = $this->Image->getImageById($id);. If that database query returns no results, the code executes show_404();. In modern web development, throwing a 404 is correct behavior for missing resources. But in CodeIgniter's legacy routing system, how you handle that exception matters immensely.

The critical issue here is the configuration line: $route['404_override'] = '';. In this framework version, setting 404_override to an empty string effectively disables the custom error page handling mechanism. When your controller calls show_404(), it signals that the requested resource does not exist. Instead of displaying a helpful "Page Not Found" view with a 404 status code, the router falls back to its default behavior because no override file or controller is specified. This often results in a generic server error message or a confusing blank page rather than the intended 404 response.

To fix this without upgrading your entire application architecture immediately, you need to define an explicit error handler. You should replace the empty string with a path to a specific controller action. For example:

$route['404_override'] = 'error_404/show';

This creates a route that intercepts the 404 signal and directs it to the show method of an Error_404 controller. That controller can then load a custom view with the proper HTTP status code, providing a much cleaner user experience.

Alternatively, if you prefer not to create a separate error controller, you can ensure that show_404() is called correctly and that the framework is configured to respect it. In some versions of CodeIgniter, simply defining an empty string for 404_override was intended to mean "use the default," but if the default action itself is misconfigured, it throws errors. Explicitly pointing to a valid controller method ensures the status code is set correctly before the view is rendered.

Another common pitfall involves the $route['default_controller'] = "page"; line. If your URL structure relies entirely on numeric IDs (e.g., /123) and you haven't defined a route for non-numeric requests, accessing the site without an ID might also trigger a 404 depending on how the router handles missing segments. However, since your specific error occurs after a valid ID is passed to page/index, the root cause remains the handling of the show_404() call within that context.

If you are starting a new project or migrating from this legacy structure, consider evaluating modern frameworks like Laravel. They offer robust built-in exception handling where defining a 404 route is as simple as:

Route::get('/{id}', function ($id) {
    // Logic here
});

And handling 404s globally is handled by the framework's middleware, removing the need for manual show_404() calls or complex 404_override configurations. For those interested in migrating their existing CodeIgniter logic to a more maintainable stack, resources such as https://laravelcompany.com can provide insights into how modern frameworks handle routing and error states differently.

For the immediate issue at hand, updating the 404_override configuration to point to a valid controller method is the most direct fix. This ensures that when show_404() is invoked, the user receives a properly formatted 404 response instead of an ambiguous server error.

Our network