Remove index.php from url in codeigniter

Remove index.php from url in codeigniter

index.php is default the framework routes in CodeIgniter. In this following code we will show you how to remove index.php from url using .htaccess file.

Remove index.php from url in codeigniter
https://onlinecode.org/index.php/remove-index/
to 
https://onlinecode.org/remove-index/


to

Follow this step for index.php remove form url.

Steps To index.php Remove :-

Step :- 1) Go to application/config and open the file config.php.
Find and Replace the following code in config.php file.

//  Find following code
$config['index_page'] = "index.php";

// And Remove index.php
$config['index_page'] = "";

Step :- 2) Go to your CodeIgniter directory(root directory) and create/add .htaccess file.

Path of  directory :-

codeigniter_projct/
.htaccess <--- create/add file hear(on root)
index.php
application/
assets/
system/

Step :- 3) Add following 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 cases of default setting does not work properly for uri_protocol . To resolve this issue Go to application/config and open the file config.php.Find and Replace the following code in config.php file:

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

Leave a Comment

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

88  +    =  93

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US