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 comment:

  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.