Codeigniter 4 remove public/index.php from URL

George Tseng
1 min readSep 1, 2022

Following are the steps.

Change App/Config/App.php

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

To

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

Clean the index page

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

This step is optional. It doesn’t make any difference to me.

public $uriProtocol = 'REQUEST_URI';

To

public $uriProtocol = 'PATH_INFO';

The following 3 steps are critical.

Copy index.php and .htaccess to app root

Visit inside public directory. And copy index.php and .htaccess to codeigniter app root directory.

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';

In some web servers, such as Apache, the following configuration needs to be set in order to work.

Find the <Directory /var/www/html>, change AllowOverride None to All and save.

<Directory /var/www/html>Options Indexes FollowSymLinks#AllowOverride None
AllowOverride All
Require all granted</Directory>

If you earlier set up app mapping to public folder in vhost, remember to change it to the app root.

<VirtualHost *:80>
ServerName website.domain.name
DocumentRoot /var/www/html/app_name/public
</VirtualHost>
To<VirtualHost *:80>
ServerName website.domain.name
DocumentRoot /var/www/html/app_name
</VirtualHost>

Then restart Apache server to take effect.

--

--

George Tseng

An application developer with extensive experience and enthusiastic about new tech currently working in IT Department of a manufacture company.