Codeigniter 3 image - w3school.info

How to remove index.php from Codeigniter url

Here we will learn how to remove index.php from codeigniter url.

Each of codeigniter constructed url contains the value index.php and excluding root url. No url cannot be run without index.php

Assume a scenario , we have a website named www.myciportal.com

Where we didn’t remove the index.php from url and i have a category with following details

category name: techbuzz

So by default it’s url will create like  following

default url : www.myciportal.com/index.php/techbuzz

it will not run like this way

www.myciportal.com/techbuzz

For make this possible we have to work on config and htaccess both and steps are following to achieve this task

If you are using mod_rewrite to remove the index.php in each url construct of codeigniter then you have to follow these steps:
Step 1: In CI Project root Folder of your project create a .HTACCESS file and place following code in it

RewriteEngine on
RewriteBase /myprojectname
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Comments :: In above code myprojectname is passed with RewriteBase , which is the demo project name of our ci project,if you are running on main domain then Redirect base will be / only , or if you are running your project in any directory then you have to specify that name.
Now Step 2:
in your project >> application/config/config.php
Replace following line

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

with

$config['index_page'] = ''; //removed the index.php after htaccess done

Now you can run your Codeigniter project and you can see the index.php has been removed from every Controller Action

Published by

Jeetendra Singh

Jeetendra Singh is a Full Stack Architect who has 12+ Years of Experience into Software Development. He is a Microsoft certified technology Specialist and AWS Certified Associate Architect. His Major Interests are in Mongo Db, Express Js, React Js, Node Js (MERN STACK), Python, DJango, Redis, Mysql, Dynamo DB , Devops, Jenkins, Cloud/Lamda , Fast Api. He build variety of applications using Python, Mern, Mean, Node, JavaScript, jQuery & PHP