Search code examples
phpcodeignitercodeigniter-2

Removing index.php from codeigniter-2


I am having problems removing index.php from codeigniter-2. I remember using the same code before too & it worked perfectly fine, but it is not working on codeigniter-2.

I have checked the documentation & this question too, still of no help.

My .htaccess code is as follows:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

Solution

  • replace /index.php with /site_folder_name/index.php everywhere & be sure that your server supports mod_rewrite

    Your new code should look like:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /site_folder_name/index.php?/$1 [L]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /site_folder_name/index.php?/$1 [L]
    
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ /site_folder_name/index.php/$1 [L]