Remove Index.php From URL in Codeigniter 4 Framwork

Codeigniter 4 Tuorial
Codeigniter 4 Tuorial

In this article we will remove index.php from URL in Codeigniter 4 framework. The directory structure of the New Codeigniter 4 framework has been changed. So you have noticed that no index.php in root directory.

You have also noticed that current url look like. Its look bad.


How to remove  public/index.php/  from URL in Codeigniter 4

Follow the steps and remove the public and index.php from URL in Codeigniter 4 framework:

Step 1: Change in App.php File

The first step is to open the app file. And make change mentioned below. You have to do this in your App.php file.

So go to project_name/app/Config/App.php and change mention below:

public $indexPage = 'index.php';
public $indexPage = '';

Step 2: Create a new index.php & .htaccess file

Yes, we don’t copy or move public folders file in root folder. We will create new two files in root folder.

A. Create index.php file and paste below code in it and save it.


   require_once __DIR__.'/public/index.php'; 



B. Create .htaccess file and paste below code in it and save it.

<files .htaccess> 
order allow, deny 
deny from all 

DirectoryIndex index.php

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]


So we have successfully removed index.php file in CodeIgniter 4. If you have any question just drop the comment. You can use other contact mode to contact me. You can find it in on my Bio. Don’t forget to share with others.

Leave a Reply