Technology Blog





Friday, October 7, 2011

Remove index.php from url of codeigniter site using htaccess

Usually when we run a CodeIgniter website, the url will have index.php after the hostname. To remove this we need to use mode_rewrite, htaccess.

First just check your php info of your server whether you have loded mod_rewrite module. To check this create  'php-info.php' file and put the following contents and run it.


echo phpinfo();

In your output, check whether in loaded modules 'mod_rewrite' is enabled or not.

If its enabled as given above, You are ready to use '.htaccess'. Otherwise you need to load the module in your server.

To remove 'index.php' from the url, create a '.htaccess' file ( no file name, just '.htaccess') in the root directory of your website where 'index.php' file of the codeigniter resides. And write the followin contents...


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1

The above code is to rewrite the url 'http://localhost/<something>' to 'http://localhost/<something>' except for folders and files.

If your website url is in the root of the server like '<something>'. To use this like '<something>' , The htaccess code in the Line 4 should be like 'RewriteRule ^(.*)$ /index.php/$1'.


  1. I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again.... Feel free to visit this website.

  2. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.php training in chennai

  3. This comment has been removed by the author.

  4. It’s not a first time when I see how useful .htaccess is. I mean, I’m not so good in php and other stuff but, it’s already 3rd guide where .htaccess is mentioned. However, I still got problems with understanding code. I don’t know maybe it’s not for me? Dunno, but I do know how high rating of is.