Today in this tutorial, if you want to remove public and index.php from url in Codeigniter 4 framework. So this tutorial will help you remove index.php in Codeigniter 4.

In this tutorial, we would love to share with you, index.php remove in Codeigniter 4, how to remove public and index.php from URLs in new Codeigniter 4 frameworks.

The directory structure of the new Codeigniter 4 framework has been changed to remove index.php from Codeigniter 4.


Step 1: Change In App.php File

The first step is to open the app.app file. And the changes mentioned below. You have to do this in your App.php file. remove index.php from url Codeigniter.

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

public $baseURL = 'http://localhost:8080';

To

public $baseURL = 'http://localhost/your_project_name/';

And the second change in the app.php file:

public $uriProtocol = 'REQUEST_URI';

To

public $uriProtocol = 'PATH_INFO';


Example 2

We can also remove index.php in Codeigniter using .htaccess. I have given the example below.

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

I hope it can help you...