Remove Public and Index.php from Codeigniter 4

Mantan Programmer
2 min readApr 26, 2022

--

How are you all friends, this time we will discuss how to remove public and index.php from URLs in codeigniter 4. Maybe this will help all friends when creating applications using codeigniter 4.

Codeigniter is quite different from previous versions, namely versions 3 and 2. For version 4 the directory structure is almost close to laravel. Because there is a public folder when accessing the url.

we just discussed how to remove public and public from codeigniter 4.

1. Change File App.php

The first step is to open the App.app file which is located in project_name/app/Config /App.php and change the below:

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

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

and

From:
public $uriProtocol = 'REQUEST_URI';

Become:
public $uriProtocol = 'PATH_INFO';

2. Copy index.php and .htaccess to the root of the project directory

Open the public directory in the root of the project directory, then copy index.php and .htaccess to the root directory of the codeigniter 4 application.

Read more: Tutorial Codeigniter 4 ~ Login dan Register

3. Change index.php in root directory

In the project root directory, open the newly copy-pasted index.php and edit the following lines:

From:
FCPATH . '.../app/Config/Paths.php'

Become:
FCPATH . 'app/Config/Paths.php'

That’s all I can say, may be useful for all friends.

Thank you…

--

--