Home > CodeIgniter, PHP > How to remove index.php from Codeigniter URL

How to remove index.php from Codeigniter URL

March 3rd, 2009

If you are using Codeigniter you are noticed that by default index.php will be included with your URL.

But you can easily remove index.php from your CodeIgniter’s URL so that your URL should be like:http://anmsaiful.net/blog/contact

To do this just follows the following steps:

  1. Open config.php from system/application/config directory and replace
    $config['index_page'] = “index.php” by $config['index_page'] = “”
  2. Create a “.htaccess” file in the root of CodeIgniter directory (where the system directory resides), open the file using your favorite text editor, write down the following script and save it:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  3. In some case the default setting for uri_protocol does not work properly. To solve this problem just replace
    $config['uri_protocol'] = “AUTO” by $config['uri_protocol'] = “REQUEST_URI” from system/application/config/config.php

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • BlogMemes
  • email
  • LinkedIn
  • Live
  • Print
  • Taggly
  • TwitThis
  • Yahoo! Buzz

$@!ful CodeIgniter, PHP , , , , , , , , ,

  1. June 16th, 2011 at 15:52 | #1

    thanks alot ya

  2. neelu
    June 21st, 2011 at 19:24 | #2

    hi your solution is not working for me ..i am following same steps as you mention above but it shows error(Class ‘controller’ not found) when i am removing index.php word from my project url

  3. June 22nd, 2011 at 13:00 | #3

    Nice tips!
    Please include “RewriteBase” keyword.

  4. rakibul
    June 26th, 2011 at 12:27 | #4

    thanks.

  5. ashique
    July 29th, 2011 at 22:03 | #5

    this solution works for me.

Comment pages
1 ... 4 5 6
  1. No trackbacks yet.