Codeigniter 404 error on inner pages [solved]

Today I happen to come across an issue with codeigniter where the homepage worked fine, however inner pages showd error 404. Details of the issue were as follows:

  1. Homepage loaded fine.
  2. Homepage with index.php in url also loaded fine
  3. Subpages didn’t load with direct url, e.g. /about
  4. Subpages worked fine when loaded with index.php in url, e.g. /index.php/about

How to solve codeigniter 404 error on inner pages

We solve it by following these steps and making sure that everything is fine.Make sure that mod_rewrite is enabled: you can check that by creating a file named info.php and adding this code to it:

<?php
echo phpinfo();

Look for mod_rewrite on this page and make sure that it is installed as is in enabled modules list.

If not, then uncomment it in this file:

/etc/httpd/conf.modules.d/00-base.conf

htaccess code for codeigniter

Secondly, make sure that .htaccess is present in the document root folder and has necessary code in it. This is the default htaccess code for codeigniter:

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

If this still don’t work, then make sure that AllowOverride is enabled in httpd conf.

Goto:

/etc/httpd/conf/httpd.conf

Edit this file and find block for /etc/www/html directory and make sure that AllowOverride is All (not none), like this:

<Directory "/etc/www/html">
    AllowOverride All
</Directory>

You’ll have to restart httpd after making changes to this file.

Restart httpd by:

sudo service httpd restart

I hope this solves your issue. If you’re still unable to load sub pages of codeigniter website and it shows error 404, please let me know.

Leave a Reply

Your email address will not be published.