In this tutorial, you will learn to remove index.php in Codeigniter from URL using htaccess file. “htaccess” refers to Hypertext Access. It is used by Apache based web servers  to control server features. The URL in codeigniter is user-friendly as we use the controller name then function name which can be easily understood by user or any third party. The URL in Codeigniter is search engine friendly also.

After Setting up Codeigniter’s Installation from previous post of “Codeigniter tutorial step by step” the next is to remove index.php in Codeigniter and create a user friendly and SEO friendly URL.

Remove index.php in Codeigniter

Steps to remove index.php in Codeigniter

  • First of all, Go to application -> config folder -> config.php. Find and replace the below code in config.php
  • // Find the Below Code
    $config[‘index_page’] = “index.php”
    //Remove index.php
    $config[‘index_page’] = “”
  • Go to your Codeigniter folder and create .htaccess file

Path :
Your website folder/
.htaccess <————- this file

  • Write below code in .htaccess file and run the URL

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

  • If the URL still doesn’t work then there might be URI protocol issue. To solve this issue you just need to open the config.php file location under application ->config -> config.php and then find and replace the code as:

//Find the below code
$config[‘uri_protocol’] = “AUTO”;
//Replace it as 
$config[‘uri_protocol’] = “REQUEST_URI”;


Here some defined steps helped you to remove index.php in Codeigniter framework using .htaccess.

Note : In some cases the URL does work fine without index.php but on hyperlinking to another URL it still shows index.php in URL . The solution for that is to check base_url defined in config.php which is located under Codeigniter Folder in application -> config -> config.php file. Find $config[‘base_url’] in config.php and check if index.php is defined in its value then remove that index.php.


Leave a Reply

Your email address will not be published. Required fields are marked *