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

calendar_month 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.

Ashwani Kumar

I'm a dedicated full-stack developer, entrepreneur, and proud owner of buildwithphp.com. I reside in India, where I draw inspiration to create helpful tutorials and tips for fellow artisans. I'm deeply passionate about technologies like Bootstrap, PHP, CodeIgniter, Laravel, Node, React, JavaScript, and jQuery. I believe in working hard consistently, which keeps me motivated and driven. Challenges are opportunities to learn, setbacks are lessons. I find inspiration in the endless potential of technology and aim to make a meaningful impact with my work.

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

Related Tutorials
View all