Codeigniter is one of the most popular PHP frameworks. If you building your own web application using CodeIgniter, You will see your website URL with index.php. Also, index.php is not searched engine friendly. So we need to remove the default index.php from URL so that the URL becomes search engine friendly and looks clean.

Read Also: PHP File Upload and Download Tutorial

In this tutorial, you will learn how to remove index.php from URL using the .htaccess file in CodeIgniter. Let’s start step by step tutorial:

Step 1:

Open the config.php file from application/config directory.  Find and Replace the below code in the config.php  file.

//find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

Step 2:

Go to your CodeIgniter root directory and create a file called .htaccess. Write the following code in the .htaccess file:

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

Step 3:

In some case, the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php“, then find and replace the below code

//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"

If this code is not working properly, you have enabled rewrite_module in your web server.

I hope these steps helped you to remove index.php from URL in the CodeIgniter framework. keep following us to learn more.

LEAVE A REPLY

Please enter your comment!
Please enter your name here