I have seen many blog posts and forum discussions answers this question with a quick fix by coping the index.php and .htaccess to the root level and change the “$pathsPath” variable. This will definitely remove the index.php from URLs.
However, Codeigniter 4 use this folder structure for security reasons.
The “public” folder holds the browser-accessible portion of your web application, preventing direct access to your source code. It contains the main .htaccess file, index.php, and any application assets that you add, like CSS, javascript, or images.
This folder is meant to be the “web root” of your site, and your web server would be configured to point to it.
So, setup the virtual hosts like this to remove the public/index.php from URLs:
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot "path-to-project/public"
<Directory "path-to-project/public">
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
If you are in shared hosting environment, change the Codeigniter 4 “public” folder name to “public_html” and place the public folder files here and upload app, system & writable folders in above server location.