Codeigniter – getting 404 Not Found error

Codeigniter – getting 404 Not Found error

We have two hosting packages at godaddy. Our live website is working fine using following .htaccess file. Website is accessible without using index.php in url.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

We used same htaccess file and same code on other hosting that is also by godaddy. We just wanted to make production and development instances seperate. But on other hosting with same code and htaccess file, website shows 404 page not found error but website works fine with index.php in url.
We have same php version on both server. Just wants to know what could be the issue?


Solution 1:

I also faced the similar problem when I move my 100% working code to dedicated Debian server. After 3 hours of research, i found out why htaccess file is not working.You need to allow overriding of htaccess in Apache Configuration.

Here are the steps.

Step 1:

Add this in htaccess file

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

Step 2:

Remove index.php in codeigniter config

$config['index_page'] = '';

Step 3:

Allow overriding htaccess in Apache Configuration (Command)

sudo nano /etc/apache2/apache2.conf

and edit the file & change to

AllowOverride All

for www folder

Step 4:

Restart Apache (Command)

sudo /etc/init.d/apache2 restart

Before you make any changes in apache2.conf file make sure to make a backup copy of that file. If you are using Debian server you can avoid sudo command. I believe you know how to connect to your server using ssh client software like putty. Comment below if this method does not work for you.

Solution 2:

You can use this. This works for me in godaddy hosting.

RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1

Solution 3:

I have faced the similar problem when I move on godaddy server.And It’s work for me.

Add this code into your .htaccess file.

<IfModule mod_rewrite.c>
    RewriteEngine On

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d

   # Rewrite all other URLs to index.php/URL
   RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

<IfModule !mod_rewrite.c>
       ErrorDocument 404 index.php

In config file:

$config['base_url'] = '';
$config['index.php'] = '';

And Set AllowOverride to All in your httpd.conf

set the correct permission on the /cache folder, rather than just making the folder writable you need to make it reclusively writable.

I hope it will work for you.

Solution 4:

Try to lowercase all your controllers. This fix the problem for me.

Solution 5:

try this one.. it’s works for me..

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

Solution 6:

in index.php you echo “test” and run .then you can check whether it is called or not.
in config file enable error log .
Make your /application/logs folder writable.
In /application/config/config.php set. $config['log_threshold'] = 4;

check the log /application/logs folder