Blog Codeigniter How to remove index.php from URL in CodeIgniter?

How to remove index.php from URL in CodeIgniter?

Codeigniter is one of the most popular MVC frameworks in the world. If you are building any application with Codeigniter, You will notice index.php included in the URL by default. The Codeigniter framework shows all the pages through one file index.php. Without this index.php file, any Codeigniter function won’t work.

What is Codeigniter and How it works?

When you want to rank your website on google, you need to create a user-friendly and search engine friendly URL. We need to remove index.php from the URL, So that the url becomes search engine friendly and looks clean. But we will need to remove index.php from the URL with proper configuration or it will show error 404 page.

Default Codeigniter URL:

Search Engine Friendly URL:

In this tutorial, I will explain how to remove index.php from URL using htaccess in Codeigniter. Let’s start

At first, We need create a htaccess in youe application root directory. htaccess file will allow us to modify rewrite rules without accessing server configuration files. .htaccess is a configuration file for use on web servers running the Apache Web Server software. So don’t add any code this htaccess file without any knowledge otherwise your application won’t work.

Steps To Remove index.php using .htaccess:

Step 1: After creating .htaccess in your application root directory, Add the following code in this file.

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

Step 2:  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";

Replace it as:

$config['index_page'] = '';

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";

Sometime it’s already set to REQUEST_URL. In this time, We don’t need to remove it.


I hope these steps helped you to remove index.php in the CodeIgniter framework using .htaccess. If you have any questions about Codeigniter, Please comment below. I will always try to reply to your comment. Keep reading our blogs. Thank You.

Moin Uddin
I am a Web Developer, Entrepreneur, and Owner of I love coding and create amazing content about programming. If you need any help on web development, contact me on Facebook.


Please enter your comment!
Please enter your name here

Most Popular