Codeigniter The requested URL was not found on this server

Codeigniter The requested URL was not found on this server

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

Stefan Bogdanescu

Founder & Senior Architect

Codeigniter The requested URL was not found on this server

Encountering a "404 Not Found" error in CodeIgniter is one of the most common hurdles when setting up routing, but it often stems from a misunderstanding of how the framework handles default controllers versus specific route overrides. In your scenario, you are trying to access localhost/reservation/ to see the login view, but the server is returning a 404 immediately. This happens because your configuration blocks the request before CodeIgniter can even interpret your routing logic.

The root cause lies in your .htaccess file. You have configured it with:

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

This configuration explicitly denies all access to the directory, regardless of whether the URL matches a valid route or not. When CodeIgniter looks for the reservation folder (or the specific controller defined in your routes), the web server intercepts the request and returns a 403 Forbidden or 404 error because no content is allowed to pass through.

To fix this, you need to enable Apache's mod_rewrite module and point it to your CodeIgniter entry file. Open your .htaccess file located in the application/ folder (or root if using the legacy structure) and replace the current content with:

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

This snippet tells Apache to check if the requested file or directory actually exists. If it doesn't (which is true for all your dynamic routes like login or book), Apache rewrites the request to index.php. This allows CodeIgniter's router to process the URL according to your $route array. Without this, your PHP code never executes, and the browser sees an empty response or a default 404 from the server.

Once the routing is corrected, you must address the logic within your controller. The error message specifically says "The requested URL was not found," which implies the router couldn't map localhost/reservation/ to any controller method. In CodeIgniter 3, accessing a folder name like reservation without a specific sub-path usually maps to the default controller defined in the route configuration.

Your current routes define:

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

This tells the framework that if someone visits /reservation/, it should load the Reservation class and call its index() method. However, if you have enabled $route['404_override'], ensure it is not pointing to a non-existent file or an empty string that fails silently in your environment.

Inside your Reservation controller, the logic flow depends on how you handle the _construct() method and the if(...some condition...) block. If the condition evaluates to true upon initial load, you redirect to book. If false, you load the login view. This is functionally correct, but be mindful of form submissions.

Your form submits via POST:

<form class="" method="POST"> 
   <div>
       <button class="btn btn-primary" name="login">Login </button>
   </div>
</form> 

When this form is submitted, the browser sends a POST request to localhost/reservation/. If your controller's index() method does not explicitly check for the _method POST flag or specific logic to handle the click, it might load the view again. While this isn't strictly a 404 issue, it is a common UX pitfall. To prevent double submissions or unintended reloads, you can add an <input type="hidden" name="_method" value="POST"> or simply rely on CodeIgniter's $_SERVER['REQUEST_METHOD'] check if you intend to handle the login logic dynamically without reloading the view immediately upon POST.

Finally, ensure your URL helper is loaded correctly in the controller's _construct(). You currently have:

$this->load->helper("url");

This is correct for generating links, but remember that the routing magic happens automatically based on the URL structure and the default_controller setting. If you want to access specific methods directly via URLs (e.g., /reservation/login), you would need to add explicit routes like $route['login'] = 'reservation/index';, though relying on the default controller for the root folder is a valid pattern in CodeIgniter 3.

By correcting the .htaccess rewrite rules and ensuring your route definitions align with the default controller, the "URL not found" error will disappear, allowing your application to load the login view as intended.

Our network