Thursday, October 23, 2014

Removing index.php From CodeIgniter URL's

In this post we shall discuss how to remove index.php from CodeIgniter ( aka CI) URL's. When ever we have a a fresh copy of CI we find URL's like:

example.com/index.php/news/article/my_article


In order to convert them in to more meaningful and SEO friendly URL's just create a .htaccess file in the CI root and add the following lines to it.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]


The above rules will be applied to all requests either with or without the index.php part. A modified version of the htaccess instructions can be found on CodeIgniter User's Guide, but it does not work for every one (including myself) and the above solution can also be found on CI Forums.

In order to create a .htaccess file in Windows do the following:

  • Just create a new text document and make the desired change and then save it using the Save As option.
  • In the Save As dialog provide the file name as ".htaccess" (within quotes)
  • In the Save as type drop down below the file name field select All Files and save the file
  • You will get your .htaccess file.

Friday, September 26, 2014