CodeIgniter: 404 Page Not Found on Live Server

CodeIgniter: 404 Page Not Found on Live Server

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

Stefan Bogdanescu

Founder & Senior Architect

The Missing index.php Entry Point on Shared Hosting

When a CodeIgniter application runs flawlessly on your local machine but immediately hits a "404 Page Not Found" error upon deployment to a live server, the issue almost invariably stems from how the web server handles directory indexing versus application entry points. The user in the scenario described correctly identified that the application and system folders are present within public_html, along with the assets and an index.php file. However, the mere presence of these files in a directory does not automatically satisfy the web server's default behavior or CodeIgniter's routing requirements.

The Role of index.php as the Gatekeeper

CodeIgniter is designed to be run through its index.php entry point. This file acts as the gateway that loads the framework, initializes the autoloader, and processes the incoming request before it reaches any controller or view. Unlike some modern web frameworks that rely on directory traversal logic to serve content directly from a folder structure, CodeIgniter expects every request to pass through this specific PHP file.

On your local development environment, you likely have Apache or Nginx configured with specific directives (such as mod_rewrite) that might redirect requests to index.php automatically, or your browser's default settings serve the first file it finds in a directory if no other configuration exists. However, shared hosting environments often differ significantly from local setups. If the web server is configured to look for an index file and finds one named index.html or even just a generic folder listing (if enabled), it might bypass your PHP entry point entirely depending on the specific MIME types and directory indexing settings.

The critical detail here is that the user mentioned they are not using an .htaccess file. This is often the root cause of 404 errors on shared hosting. Without an .htaccess file containing RewriteRule directives, Apache will not rewrite requests like /dashboard or /api/v1/users to index.php. Even if you have defined these routes in your application/routes/default.php, the framework will never see them unless the request is first routed to the entry point.

Configuring .htaccess for CodeIgniter 3 and 4

To resolve this, you must ensure that all requests are redirected to your application's index.php before they reach the directory listing or any other handler. Below is a standard configuration tailored for Apache servers commonly found on shared hosting:

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Serve existing files and directories directly (CSS, JS, Images)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Route everything else to index.php
    RewriteRule (.*) index.php/$1 [L]
</IfModule>

This configuration tells Apache to check if the requested file or directory exists. If it doesn't (which is the case for most dynamic routes), it appends your request to index.php and passes it along. This allows CodeIgniter's internal router to handle the logic defined in your config/routes.php.

If you are using a server that supports Nginx instead of Apache, the configuration would look different, typically involving an location block that proxies requests to /index.php. However, many shared hosts default to Apache modules.

Verifying File Permissions and Structure

Another potential pitfall involves file permissions. Even if .htaccess is correctly configured, if the public_html directory has restrictive permissions (e.g., 700 instead of 755), the web server process may not be able to read the index.php file or execute it, resulting in a 404 error or a generic internal server error that mimics a missing page. Ensure your public_html directory and all contained files are readable by the web server user (often www-data, _apache, or nobody).

Additionally, double-check that the file you uploaded as index.php is indeed the one located in the root of public_html. Sometimes, developers accidentally upload a renamed version (like index_new.php) or place it inside an app subdirectory, expecting the server to find it. The URL path must match the physical location relative to the domain root.

Debugging with base_url and Routes

The user mentioned adjusting $config['base_url'] in config.php. While this configuration is vital for generating correct asset links and redirects, changing it will not fix a 404 caused by missing entry point routing. If your .htaccess is missing, the framework might try to load from a non-existent path defined by that base URL, but the primary blocker remains the lack of rewrites.

If you are still encountering issues after adding the .htaccess rules, check the log_path setting in your application/config/config.php. Ensure that log files are writable, as errors related to permissions or routing misconfigurations are often logged there. Look for messages indicating that the framework could not locate the requested controller or method.

Finally, consider the possibility of conflicting file names. If you have an index.html file in your public_html directory alongside index.php, and your .htaccess is missing or misconfigured, Apache might serve the HTML file directly for root requests while failing to route dynamic paths correctly if it doesn't follow the standard rewrite pattern. Removing unnecessary static index files can sometimes resolve these routing ambiguities.

For developers transitioning between frameworks, remember that CodeIgniter's strict entry point requirement differs from Laravel's default behavior, where public/index.php is often the only file served due to similar .htaccess configurations, but the underlying logic for handling requests without explicit rewrites varies by framework design. If you need further assistance with specific hosting environment configurations or advanced routing strategies, resources like LaravelCompany can offer insights into modern web application deployment practices that may also apply to legacy frameworks.

Our network