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. Keith Ritt
    May 4th, 2009 at 02:52 | #1

    THANK YOU!!!!

    I have searched up and down for this answer. Included codeigniter.com and textbooks – No one has mentioned the editing of $config['uri_protocol']

  2. June 11th, 2009 at 23:10 | #2

    Thanks man, many other solutions made trouble.

  3. JG
    June 27th, 2009 at 06:21 | #3

    This does not work with Uniform Server on Windows.

  4. Rakibul Hasan
    August 4th, 2009 at 19:39 | #4

    Wow !! thanks really helpful. I have been suffering with htaccess. And now it’s working. You rulz :)

  5. Alif
    August 11th, 2009 at 13:49 | #5

    @JG : you need to edit httpd.conf in apache dir to enable mod_rewrite module. I’m uniform server user and CI can work in it seamlessly. give it a try ;)

  6. September 3rd, 2009 at 09:06 | #6

    thank you ,
    now my web site is working properly.

  7. Greg Jones
    October 26th, 2009 at 01:46 | #7

    the last line should read (you forgot the ? after the index.php):

    RewriteRule ^(.*)$ /index.php?/$1 [L]

  8. October 26th, 2009 at 15:39 | #8

    No need to use the “?” sign… :)

  9. Kaal Purush
    October 30th, 2009 at 15:17 | #9

    One more thing your mod_rewrite.so apache module should have to be enabled. Open httpd.conf and change #LoadModule rewrite_module modules/mod_rewrite.so by LoadModule rewrite_module modules/mod_rewrite.so

  10. alhamdulillah
    November 23rd, 2009 at 11:13 | #10

    what name in “.htaccess” ? any name ? please and thank you.

Comment pages
1 2 3 ... 6
  1. No trackbacks yet.