Codeigniter remove index.php from URL using htaccess

Codeigniter remove index.php from URL using htaccess

CodeIgniter is a powerful and fastest PHP framework. Codeigniter has reach Library for the developer. By default, the Codeigniter have include index.php for all URLs. So, Today we are going to learn How to remove the Codeigniter remove index.php from URL.

We can remove index.php from URL by following some easy steps. We use htaccess for removing the index.php from all URL. Just follow the below steps.

Codeigniter remove index.php

First of all, We are going to create the “.htaccess” file in the root directory if not exists. Now, let’s open the “.htaccess” file then write the below code.

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

We are ready with the htaccess, Now, we are going to change the Codeigniter configuration for remove index.php from URL. So let’s open “application/config/config.php” file and change the base_url and index_page options like below.

$config['base_url'] = '';

$config['index_page'] = '';

First of all, Set the base_url that is required so don’t forgot to set base_url before start working with Codeigniter. Then after we are going to remove index.php from index_page on configuration file like above.

Now you can access the Codeigniter welcome screen without index.php like

If you face any issue write the comment.