How to remove index.php in codeigniter?


How to remove index.php in codeigniter?

Codeigniter | Remove index.php from url in codeigniter?

The file index.php is root file of codeigniter. it's contains setting code for CodeIgniter. So, when we redirect to other pages the url comes with index.php which looks ugly and also not good for seo points of view. we can simplify say that the url is not user friendly.

The url look like this:



Now for removing the index.php form the url we need to do same simple step:

Step1: Open the config.php file located in "/application/config" folder. Find and modify the below code.

 //  Find the below codes

$config['index_page'] = "index.php"

$config['uri_protocol'] = "AUTO"

//  replace with these codes

$config['index_page'] = ""

$config['uri_protocol'] = "REQUEST_URI" 

Step2: Create a .htaccess file in project root directory. The .htaccess file is use to modify or change configration of apache server. Below code tells apache server to ignore index.php in requested uri. Copy the below code in .htaccess file.

It should be located as:

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