Wednesday, September 8, 2010

Removing the 'index.php' from the URL of a codeigniter site

UPDATE (9th May 2015): at the time of writing this article, codeigniter was on version 1.7 I guess. Now, in codeigniter version 2.2.2, the official documentation of Codeigniter shows how to achieve this goal very easily. You can refer to the "Removing the index.php file" section in page.

By default, the index.php file will be included in your URLs:

You can easily remove this index.php from displaying in the url by using a .htaccess file in your 'codeigniter' root folder and make it look like:

Notice the absence of anything infront of the (.) dot in the filename of .htaccess file

Here is an example of such a .htaccess file.

In the above example, any HTTP request other than those for index.php is treated as a request for your index.php file.

If your installation is not in the server root, you will need to amend the RewriteBase line from “RewriteBase /” to “RewriteBase /folder/”

If you had renamed your system folder, you will need to amend the RewriteCond line to replace the name 'system' by the new name you have selected

Remember to, edit the /application/config/config.php file so that $config['index_page'] = "". (i.e. an empty string)