CodeIgniter 4 – How To Remove “public” From URL

In this post, we will show you how to remove “public” from URL in CodeIgniter 4 (CI4) framework.

Here are some CI4 URL examples containing “public“:

http://localhost/MyCodeIgniter4App/public/
http://localhost/MyCodeIgniter4App/public/register

https://yourdomain.com/public/
https://yourdomain.com/public/register

You want to remove “public” from the URL, i.e. it will become:

http://localhost/MyCodeIgniter4App/
http://localhost/MyCodeIgniter4App/register

https://yourdomain.com
https://yourdomain.com/register

To do this, let’s follow the following 2 steps:

Step 1: In public/ directory, copy index.php and .htaccess to your root project directory.

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

change:

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

to:

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

That’s all.

Leave a Reply

avatar