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. Dijo
    May 20th, 2010 at 00:02 | #1

    Amazing!! I have tried some other but this one worked perfectly. Thanks dude.

  2. mashuq
    May 27th, 2010 at 13:52 | #2

    thanks man, it worked fine while others didnt. thanks again.

  3. kerel
    May 28th, 2010 at 23:50 | #3

    In wamp , rule from CodeIgniter works for me when remove the slash

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

    by the way, great job man :)

  4. arie
    May 29th, 2010 at 15:20 | #4

    your .htaccess really work, thx dude :D

  5. Maulik
    June 14th, 2010 at 19:37 | #5

    Thanks. Your .htaccess finally worked like a charm.

  6. jay
    June 27th, 2010 at 00:16 | #6

    your’e a really a genius. this works like a charm!

  7. Mohammad Jabali
    August 30th, 2010 at 07:48 | #7

    Thank,
    but not work !
    Internal Server Error !

  8. September 1st, 2010 at 14:41 | #8

    You might did something wrong in your .htaccess or httpd.conf file. Please double check them.

Comment pages
  1. No trackbacks yet.