in Codeigniter, Web Development

Codeigniter remove index.php

Hola Amigos (Hello Friends in Spanish) ๐Ÿ™‚ , In this post I am going to show how do we remove index.php in Codeigniter.

While you install fresh Codeigniter your URL is some thing like this:

example.com/index.php/class/function/ID

But this URL structure is not so much charming and is also not much SEO friendly. So we would like to change above URL to something life this:

example.com/class/function/ID

To modify the URL you need to enable mod_rewrite module first, since itโ€™s initially disabled in apache configuration file. Open httpd.conf and search for โ€œmod_rewriteโ€. If you are a WAMP user like me than to find httpd.conf in your Taskbar click WAMP icon -> Apache->httpd.conf. You will find a line with following text.

#LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c

Uncomment the lines (remove the trailing #) like this:

LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c

Than you need to restart the WAMP or whatever server you are using.

Now next step to to create a .htaccess file with following code.

Now if you remove index.php from you URL then it would perfectly work. In some of the server we will find error showing “No input file specified”. Then we need to just add โ€œ?โ€ after index.php and it will solve problem.

I hope this small post would help you some how. Happy Coding.

Reference
http://ellislab.com/codeigniter/user-guide/general/urls.html