While working with Codeigniter we may see that 404 error is one of the common error which may occur if the configuration is not done properly. If you are moving your site from a local server to a live website or from one hosting to another this issue can happen.
Fixing Error 404 is easy in Codeigniter but you have to make sure that you are doing in properly.
There are multiple ways in which you can try and fix the 404 error (404 Error Page Not Found) in Codeigniter and PHP.
1. Checking the config/config.php page and see if the code is matching as below or not, if its not then you have to update it as given below and replace http://example.com with your domain name
/* your base url or your domain name for your application*/
$config['base_url'] = "http://example.com";
/*For your default index page generally this is empty */
$config['index_page'] = '';
2. check the .htaccess file and make sure it’s not having any errors in it. It has to reflect as given below.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
3. Using the capitalize form of text for your controllers and file names.
Files’ names:
- Controllers | in controllers folder: About_controller.php
- Models | in models folder: About_model.php
- Views | in views folder: About.php
If there are any file names that are having a small case letter either in models, views, or controller then you have to replace it with the capitalize form so that it can hide the 404 error.
Comments