CodeIgniter .htaccess and index.php issues – Solution

CodeIgniter index.php and .htaccess issue ruined my last night. I’ve solved this simple issue many times before but not any solution was working that time.

Few days before today, I was working in a client project which I’ve been demonstrating to my client from my personal demo server which is a HostGator Baby Plan Hosting.  The site was running fine in my local pc (Win7 running XAMPP 1.7.7 running the site in VirtualHost) and in my demo server but when I push the code in client’s staging server (Rackspace Cloud server with CentOS 6.4, Apache2 ) , I was getting a 404 Page Not Found error message. First I checked my .htaccess file and it was same as my demo server, same as my local pc which is

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

In my config.php file, I set

$config['base_url'] = '';
$config['index_page'] = '';

but nothing was working. I tried every solution I used before and I found over Internet but couldn’t find any perfect solution to solve my problem.

Everything seems fine and I was getting frustrated. Finally one solution I found where it says, I’ve to edit my httpd.conf file

httpd.conf File location in CentOS 6.4
httpd.conf File location in CentOS 6.4

and change AllowOverride None to AllowOverride All and saintly this solution worked Perfectly.

VirtualHost settings
VirtualHost settings to remove index.php file in CentOS 6.4

What Problem this was?

With my little understanding on server things, I understand that though we set the rule in .hetaccess to remove the index.php file, it was not fully permitted by staging.conf file. When working in Windows with XAMPP, this file location is in your drive:\xampp\apache\conf\extra\httpd-vhosts.conf

If you still reading, let me know if the solution work for you or If I need to update this posting in anywhere. I am open to creative suggestions 🙂

Published by

Ariful Haque

Software Engineer | Freelance Web Application Developer PHP, CodeIgniter, WordPress, JavaScript, jQuery, Ajax, Ubuntu, CentOS, Apache..

15 thoughts on “CodeIgniter .htaccess and index.php issues – Solution”

  1. Hi Ariful Haque
    I also face the same problem that you are talking about but the solution that you mention is not working for me. i tried very hard and then find a different solution which is below….

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

    I hope my response will helpful for you…

    1. Hi Anand

      Thanks for sharing your solution here. Is your site is in sub folder? Why you add folder before index.php in this line “RewriteRule ^(.*)$ /folder/index.php/$1 [L]” ? This line is the difference between your and my .htaccess.

  2. This worked, thanks. I was driven berserk trying different .htaccess files and clawing my eyes out wondering why nothing worked. I must have been a solid hour farting around with this nonsense. I hate web dev sometimes, it’s so easy to get sucked into non-productive black-holes over something stupid.

  3. Hi,
    I am having problem in setting with codeignitor in Kloxo panel., It gives 404 not found error. also ther is no staging.conf file on my server. Im using Centos to host kloxo panel, Ihave made the .htaccess changes that you have recommended, Please help me if you have any solution to how to configure codeignitor on Kloxo, it will be great help,

    I am attaching my config file also
    $config[‘base_url’] = ‘’;

    | Index File
    | Typically this will be your index.php file, unless you’ve renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    $config[‘index_page’] = ‘ ‘;
    | This item determines which server global should be used to retrieve the
    | URI string. The default setting of ‘AUTO’ works for most servers.
    | If your links do not seem to work, try one of the other delicious flavors:
    | ‘AUTO’ Default – auto detects
    | ‘PATH_INFO’ Uses the PATH_INFO
    $config[‘uri_protocol’] = ‘AUTO’;


  4. hi sir, i’m currently studying the CI framework when i upload my project on web server, I got 404 not found. I’m using CI 2.2

  5. i have problem with index.php

    Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80

    i have follow all above but not working for me.

    pls help me if any body has solution.

  6. I use CodeIgniter.

    I route certain urls to different files based on the structure of url using the routes.php file. Everything has been working fine.

    However, a few months ago, i thought i would add a custom 404 page. I did and things appeared to be working fine.

    HOWEVER, i have just realised that every page on my site (except the home page) gives a server response of 404 error and yet displays to the human user the correct page as the custom page!

    I have no idea how that’s happening but it’s obviously a nightmare as i am now not indexed from all search engine listings!!! Domain is

    What code should i post to help ??

  7. hi, my site was running fine in my local pc, now in a hosting buyed last night, appears this:
    Index of /

    What i’m doing wrong?

    pls help

Leave a Reply

Your email address will not be published. Required fields are marked *