How To Remove Public/index.php/ From URL In Codeigniter 4

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 how to 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 the new Codeigniter 4 frameworks.

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

How To Remove [public/index.php] URL In Codeigniter 4 - Step By Step

you follow the below-given steps and easily 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 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';


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

And the second change in the app.php file:

public $uriProtocol = 'REQUEST_URI';


public $uriProtocol = 'PATH_INFO';
Step 2: Change In Index.php

In the root project directory, open index.php and edit the following line:

$pathsPath = FCPATH . '../app/Config/Paths.php';

 change TO

 $pathsPath = FCPATH . 'app/Config/Paths.php';
Next Example:

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

Leave a Reply

Your privacy will not be published. Required fields are marked *

We'll share your Website Only Trusted.!!