CodeIgniter works locally but every page is 404 on the live server
404 Page Not FoundShort answer
A 404 on the live server comes from one of four places: the document root is not the public folder, Apache ignores .htaccess or nginx has no try_files rule, the route is not defined because auto routing is off, or the controller file name differs from its class in case. Test index.php directly to tell them apart.
Fix it fast
1Find out which cause you have
Request the front controller directly. If it works but nice URLs fail, the web server rewrite is the problem. If it also fails, look at the document root. If it renders a CodeIgniter 404, look at routes and controllers.
curl -I https://example.com/index.php curl -I https://example.com/index.php/about2Match what you see, then jump to its fix
- 1
The web server 404s the URLs, while the app works when started from the public folderThe document root is the project folder, not publicFix - 2
index.php works, but any other URL gives the web server's own 404 pageApache ignores .htaccess, or mod_rewrite is offFix - 3
The nginx 404 page appears for every URL except /index.phpnginx has no rule that sends unknown URLs to index.phpFix - 4
CodeIgniter's own 404 page appears for a controller that exists and worked on an older setupThe route is not defined, because auto routing is offFix - 5
The controller file exists, but its URL gives a 404 and the file name and class name differ in caseThe controller file name does not match its classFix
- 1
What does the error look like?
404 Page Not FoundThe requested URL was not found on this server.
Cause 1 of 5
The document root is the project folder, not public
1Check
CodeIgniter 4 is designed to run from the public folder, which must be the document root. Check the root in the web server config.
grep -rn "DocumentRoot\|root " /etc/apache2/sites-enabled/ /etc/nginx/sites-enabled/2Fix
Point DocumentRoot (Apache) or root (nginx) at the public folder of the project, and set AllowOverride All on it for Apache.
DocumentRoot /var/www/my-app/public
<Directory /var/www/my-app/public>
AllowOverride All
</Directory>3Verify
Test the config, reload, and request the home page.
sudo apache2ctl configtest && sudo systemctl reload apache2
curl -I https://example.com/Confirmed by codeigniter.com
Cause 2 of 5
Apache ignores .htaccess, or mod_rewrite is off
1Check
The rewrite rules in public/.htaccess only apply when mod_rewrite is enabled and AllowOverride permits them.
apache2ctl -M | grep rewrite
ls -la /var/www/my-app/public/.htaccess2Fix
Enable mod_rewrite, set AllowOverride All for the public folder, and reload Apache.
sudo a2enmod rewrite
sudo systemctl reload apache23Verify
Request a route that is not a real file.
curl -I https://example.com/aboutConfirmed by codeigniter.com
Cause 3 of 5
nginx has no rule that sends unknown URLs to index.php
1Check
nginx does not read .htaccess. It needs try_files in the server block, and PHP files passed to PHP-FPM.
sudo nginx -T 2>/dev/null | grep -n "try_files\|root"2Fix
Add the documented try_files rule inside the location for the site.
location / {
try_files $uri $uri/ /index.php$is_args$args;
}3Verify
Test the config, reload nginx and open a route.
sudo nginx -t && sudo systemctl reload nginxConfirmed by codeigniter.com
Cause 4 of 5
The route is not defined, because auto routing is off
1Check
Since 4.2.0, auto routing is disabled by default, so only routes defined in the routes file match.
grep -n "autoRoute" app/Config/Routing.php2Fix
Define the route explicitly in app/Config/Routes.php.
// app/Config/Routes.php
$routes->get('about', 'Pages::about');3Verify
Request the URL again.
curl -I https://example.com/aboutConfirmed by codeigniter.com
Cause 5 of 5
The controller file name does not match its class
1Check
The controller file name must match the class name including case, with an uppercase first letter and the rest lowercase for auto routing. Compare the file with the class.
ls app/Controllers/
grep -n "^class" app/Controllers/*.php2Fix
Rename the file to match the class exactly. If you want another naming style, define the route manually with the full class name.
$routes->get('helloworld', '\App\Controllers\HelloWorld::index');3Verify
Request the URL again.
curl -I https://example.com/helloworldConfirmed by codeigniter.com
How do I stop it coming back?
- Make deploy scripts set the document root to public and keep the web server config in version control.
- Test on the same OS and web server as production, or in a container that matches it.
- Define every route in Routes.php and keep auto routing off.
- Set baseURL in .env for each environment.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
Chrome shows net::ERR_INCOMPLETE_CHUNKED_ENCODING on a PHP page
The page loads partly, then the response stops
The browser got a chunked response that ended before its final zero-length chunk, so the connection closed mid-page.
2 causes, each with a fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fixBack end
Laravel routes return 404 or throw NotFoundHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
A 404 means Laravel found no route for that URL, or the request never reached Laravel at all.
3 causes, each with a fixBack end
Livewire uploads work locally but fail behind nginx on the server
$_POST and $_FILES are empty (PHP discards a body over post_max_size)
Three separate limits stop a large upload, and a local dev server hides two of them.
3 causes, each with a fixBack end
Your plain PHP endpoint sets CORS headers but the browser still blocks it
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/save.php:1)
The headers only help if they are sent on every response the browser looks at, starting with the OPTIONS preflight.
3 causes, each with a fixBack end
echo and flush() in PHP show nothing until the script finishes
flush() has no visible effect in the browser
flush() only empties PHP's own system buffers.
2 causes, each with a fix