How To Remove Index.Php From CodeIgniter

CodeigniterRemoveIndex

In this tutorial i am going to show how to remove index.php from url using htaccess file in CodeIgniter. Basically it’s define URL rewrite. By default index.php file will be included in your URLs. You can easily remove this file by using a CodeIgniter htaccess file with some simple rules. Here is an example of such a file.

Step:-1 Open the folder “application/config” and open the file “config.php”. find and replace the below code in config.php file.

//find the below code
$config[‘index_page’] = “index.php”
//replace with the below code
$config[‘index_page’] = “”

Step:-2 Go to your CodeIgniter folder and create .htaccess file

Step:-3 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]
</IfModule>

Step:-4 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php”, then find and replace the below code

//find the below code
$config[‘uri_protocol’] = “AUTO”
//replace with the below code
$config[‘uri_protocol’] = “REQUEST_URI”

Hope these steps helped you to remove index.php from url in CodeIgniter framework using .htaccess.