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. January 21st, 2010 at 00:34 | #1

    i salute you, thank you sir. may Allah protect you my brother :)

  2. Hossein Salemi
    January 28th, 2010 at 19:10 | #2

    Thank a milion!!!

  3. rasel
    February 26th, 2010 at 11:47 | #3

    Hi,
    I am new to php + CodeIgniter. I am trying to learn it from the CodeIgniter documentation. But I am not clear about the instruction “Create a “.htaccess” file” — what is this actually…??? is it a file extension ?

  4. February 26th, 2010 at 15:06 | #4

    “.htaccess” is actually a file extension. Purpose of this files are handling apache server requests manually. For details please google.

  5. March 20th, 2010 at 20:23 | #5

    @rasel
    Hi, Great! Just what I needed, although I had to fiddle around with the slashes :-)
    And… for great tutorials, that helped me learn CI fast go to http://net.tutsplus.com/ and search for CodeIgniter… they have a series on how to build an almost complete CMS!

  6. Yun
    March 20th, 2010 at 21:24 | #6

    Cool!
    it helps alot.

    i wonder if you can explain what in the whole wide world each line does

    tq

  7. Sujoy
    April 18th, 2010 at 14:12 | #7

    Superb!
    Thank a lot. It works fine with my PHP installed as Apache Module.

  8. Priya
    April 27th, 2010 at 13:54 | #8

    Thanks.. Its working..

  9. May 13th, 2010 at 15:21 | #9

    Thank you!))good post..!

  10. ganesh
    May 16th, 2010 at 02:48 | #10

    thanks a lot. very useful

Comment pages
  1. No trackbacks yet.