Remove index.php by .htaccess – CodeIgniter

In this tutorial we are going to learn how to remove index.php from URL using .htaccess file in CodeIgniter. .htaccess is the shortened used for Hypertext Access, which is a powerful configuration file that controls the directory “.htaccess”. It is used by Apache based web servers to control various server features.

Step:-1  Open the file config.php located in application/config path.  Find and Replace the below code in config.php file.

//  Find the below code
$config['index_page'] = "index.php";
//  Remove index.php
$config['index_page'] = "";

Step:-2  Go to your CodeIgniter folder and create .htaccess file at Application folder level. Write below code in .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Step:-3  In some cases the default setting for uri_protocol does not work properly. To solve this issue just open the file config.php located in application/config and then find and replace the code as:

//  Find the below code
$config['uri_protocol'] = "AUTO";
//  Replace it as
$config['uri_protocol'] = "REQUEST_URI";


Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.