[php] CodeIgniter 404 Page Not Found, but why?

I am using CodeIgniter for two applications (a public and an admin app). The important elements of the document structure are:

/admin
/admin/.htaccess
/admin/index.html
/application
/application/admin
/application/public
/system
.htaccess
index.php

The /admin/.htaccess file looks like this:

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

The /admin/index.php has the following changes:

$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)

And the /application/admin/config/routes.php contains the following:

$route['default_controller'] = "welcome";
$route['admin'] = 'welcome';

Welcome is my default controller.

When I call up the Domain/admin I get a 404 Page Not Found error. When I call up the Domain/admin/welcome everything works fine. In the debug logs I get the following error message:

DEBUG - 2010-09-20 16:27:34 --> Config Class Initialized
DEBUG - 2010-09-20 16:27:34 --> Hooks Class Initialized
DEBUG - 2010-09-20 16:27:34 --> URI Class Initialized
ERROR - 2010-09-20 16:27:34 --> 404 Page Not Found --> admin

Weirdly enough this setup works perfectly on my local MAMP installation (with the localdomain/admin/), but when I publish and test it on the "live" server, I just get 404 errors.

Any ideas? What am I doing wrong? Thanks C.

This question is related to php codeigniter routes http-status-code-404

The answer is


Leaving this answer here for others who ran into my situation.

My codeigniter app was working fine in localhost/WAMP, but was unable to route and produced 404 not found errors when pushing to an AWS EC2 instance. My issue was solved from the answer from HERE htaccess works in localhost but doesn't work in EC2 instance

(route to my admin page) {domain}/admin was producing 404

the /etc/httpd/conf/httpd.conf file needs to be modified.

-after every instance of "DocumentRoot "/var/www/html"" (2 places) "AllowOverride None" needed to be changed to "AllowOverride All".

Restarted the EC2 instance from the AWS dashboard.

{domain}/admin is now accessible and working as intended.

hope this helps someone else like it helped me!


Your folder/file structure seems a little odd to me. I can't quite figure out how you've got this laid out.

Hello I am using CodeIgniter for two applications (a public and an admin app).

This sounds to me like you've got two separate CI installations. If this is the case, I'd recommend against it. Why not just handle all admin stuff in an admin controller? If you do want two separate CI installations, make sure they are definitely distinct entities and that the two aren't conflicting with one another. This line:

$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)

And the place you said this exists (/admin/index.php...or did you mean /admin/application/config?) has me scratching my head. You have admin/application/admin and a system folder at the top level?


I had the same issue after migrating to a new environment and it was simply that the server didn't run mod_rewrite

a quick sudo a2enmod rewrite then sudo systemctl restart apache2

and problem solved...

Thanks @fanis who pointed that out in his comment on the question.


we have to give the controller name in lower cases in server side

$this->class = strtolower(__CLASS__);

In my case I was using it on localhost and forgot to change RewriteBase in .htaccess.


You could try one of two things or a combination of both.

  1. Be sure that your controller's name starts with a capital letter. eg "Mycontroller.php"
  2. If you have not made any changes to your route, for some strange reason, you might have to include capital letters in your url. e.g if your controller is 'Mycontroller.php' with a function named 'testfunc' inside it, then your url will look like this: "http://www.yourdomain/index.php/Mycontroller/testfunc". Note the capital letter. (I'm assuming you haven't added the htaccess file to remove the 'index.php' part. If you have, just remove it from the url.)

I hope this helps someone


It happens cause of multiple reasons but the answer missing above there's the "className" while extending your controller.

Make sure your class name is the same as your controller name is your controllers. e.g., If your controller name is Settings.php, you must extend the controller like.

class Settings extends CI_Controller
{
// some actions like...
     public function __construct(){
     // and so and so...
     }
}

If your application is in sub-folder then the Folder name in directory and URL must be same (case-sensitive).


If you installed new Codeigniter, please check if you added .htaccess file on root directory. If you didn't add it yet, please add it. You can put default content it the .htaccess file like below.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

  1. Change your controller name first letter to uppercase.
  2. Change your url same as your controller name.

e.g:

Your controller name is YourController

Your url must be:

http://example.com/index.php/YourController/method

Not be:

http://example.com/index.php/yourcontroller/method


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to codeigniter

DataTables: Cannot read property 'length' of undefined How to set time zone in codeigniter? php codeigniter count rows CodeIgniter: 404 Page Not Found on Live Server Only variable references should be returned by reference - Codeigniter How to pass a parameter like title, summary and image in a Facebook sharer URL How to JOIN three tables in Codeigniter how to get the base url in javascript How to get id from URL in codeigniter? How to disable PHP Error reporting in CodeIgniter?

Examples related to routes

How to open a link in new tab using angular? How to Refresh a Component in Angular laravel Unable to prepare route ... for serialization. Uses Closure How to use router.navigateByUrl and router.navigate in Angular No provider for Router? Difference between [routerLink] and routerLink How to force Laravel Project to use HTTPS for all routes? Change route params without reloading in Angular 2 Angular 2 router no base href set How to redirect to a route in laravel 5 by using href tag if I'm not using blade or any template?

Examples related to http-status-code-404

Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Vue-router redirect on page not found (404) Apache: The requested URL / was not found on this server. Apache Tomcat Servlet: Error 404 - The requested resource is not available Django, creating a custom 500/404 error page TOMCAT - HTTP Status 404 Object not found! The requested URL was not found on this server. localhost Getting 404 Not Found error while trying to use ErrorDocument Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available" MIME types missing in IIS 7 for ASP.NET - 404.17