Codeigniter 4 Remove Public Index.php file from url

Codeigniter Remove Index.php file from url example; In this tutorial you will learn how to remove public and index.php from URL in Codeigniter 4 framework. In any app php run using index.php file and its not great to show index.php file in url so we want to remove public index.php from url.

Let’s follow the below given steps and easily remove the public and index.php from URL in Codeigniter 3 or 4 framework:

Step 1: Change in App.php File

First open the project_name/app/Config/App.php file and change the base url same as bellow:

So go to project_name/app/Config/App.php and change mention below:

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

To

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

Now second change in the app.php file:

public $uriProtocol = 'REQUEST_URI';

To

public $uriProtocol = 'PATH_INFO';

Step 2: Copy index.php and .htaccess

Now go inside the public directory and copy index.php and .htaccess to codeigniter app root directory because if we add the index.php and .htaccess file in our application root inside then we don’t show the index.php file in url.

Step 3: 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';

If the above solution is not work for; so you can configure your apache server; as shown below:

In the apache server, the mode rewrite is already on. But some default values need to be changed on /etc/apache2/apache2.conf file. Following are changes,

First, find

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

And change AllowOverride None to All and save.

Then enable mode rewrite using the command(In this case already enabeled),

sudo a2enmod rewrite

Then restart the server,

sudo /etc/init.d/apache2 restart

In this tutorial, you have learned how to remove the public and index.php in new Codeigniter 4 framework. I hope its works for you..

Leave a Comment