Remove "index.php" from url in Codeigniter 3 using htaccess

30 Apr 2022 | Codeigniter


In this tutorial, you will learn how to remove index.php from url in CodeIgniter 3 using htaccess. Codeigniter 3 includes index.php in the url by default, but we need to remove it to make the application or website URLs search engine friendly, the search engine also recommends a clean and professional URL. You can remove index.php from URL in Codeigniter 3 by following the steps given below.

Step 1: Create a .htaccess file

Codeigniter allowed us to remove index.php from the URL by writing a part of the code in .htaccess file, so first of all, we will need to create an .htaccess file in the root directory of CodeIgniter project.

Let's create a .htaccess file in the root directory and add the following code to this file.

.htaccess

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

Step 2: Remove index.php from config file

Open the config.php file and make the following changes

Change:

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

To:

$config['index_page'] = '';

Now you will have your search engine-friendly URLs.

Buddy! I hope you relished the tutorial, and it was good to see you again. Keep learning. Keep visiting.

Related Blogs