How to remove index.php in Codeigniter

In the CodeIgniter, the index.php data will be included in the link by default yet to make it search engine friendly and straightforward, we require to remove it. In this article, we will find out just how to eliminate index.php in Codeigniter.

What is CodeIgniter?

CodeIgniter is a PHP driven framework for application development rapidly.

While constructing an internet application, we spend a lot of time composing the very same code repeatedly. Frameworks give us a beginning block and decrease the quantity of code needed to construct an internet site.

CodeIgniter is a free, open-source, easy-to-use, object-oriented PHP internet application framework. CodeIgniter is based upon the MVC, it has complete system for attaching to the database and doing different procedures like sending e-mails, publishing documents, etc.

For making use of Codeigniter, it is excellent to have some basic understanding of PHP syntax and just how to communicate with data sources and HTML.

Why remove index.php?

Removing index.php makes the URL look cleaner and more better. The Codeigniter structure offered all the sights via the one file index.php. Without this file, no model/views/controller won't function. We need to get rid of the index.php from link with proper setup otherwise it will certainly show 404 page.

Exactly how to eliminate index.php?

1. Create a .htaccess file

To start with we will require to produce a .htaccess data in our project's root directory. Creating a .htaccess file will allow us to customize our url rewrite rules without accessing server setup files. As a result of this factor, .htaccess is vital to our internet application's safety therefore makes sure that the file is hidden .htaccess is an acronym made use of for Hypertext Accessibility, it is an arrangement documents that regulates the directory ". htaccess".

add the following code to this file.

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

2. Delete index.php file

Open the config.php file in your text editor and remove index.php

Replace

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

To

$config['index_page'] = "";

Also Change

$config['uri_protocol'] = "AUTO";

To

$config['uri_protocol'] = "REQUEST_URI";

3. Tweaks in Apache Server Configuration

Enable apache rewrite mode with following command.

sudo a2enmod rewrite

Finally Restart Apache server

sudo service apache2 restart

It's Done. Hope this article helps you to remove index.php from url in codeigniter.