Remove the words “public”and “index.php”from the URL in Codeigniter 4.

In codeigniter, how can I remove index.php? Remove public and index.php from the URL in the Codeigniter 4 framework. As a result, you’ll benefit from this instruction.

We’d like to show you how to remove public and index.php from URLs in the new Codeigniter 4 frameworks in this tutorial.

The New Codeigniter 4 framework now has a different directory structure.

In Codeigniter 4, how can I get rid of public/index.php/ from the URL?

Remove the public and index.php from the URL in the Codeigniter 4 framework by following the steps below:

Step 1: Make a change to the App.php file.

The app.app file must first be opened. As well as the modifications listed below. This must be done in the App.php file.
So, navigate to project name/app/Config/App.php and make the following changes:

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

The second update in the app.php file is as follows:

public $uriProtocol='REQUEST_URI';
To
public $uriProtocol='PATH_INFO';

Step 2: Make a copy of the index.php and.htaccess files.

Enter the public directory. Also, copy index.php and.htaccess to the root directory of the Codeigniter app.

Step 3: Modify index.php

Open index.php in the root project directory and make the following change:

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

If the following technique does not work for you, you can set up your Apache server as follows:

The rewrite mode is already enabled in the Apache server. However, some default variables in the /etc/apache2/apache2.conf file must be altered. The following are the modifications:


Options Indexes FollowSymLinks
AllowOverride None
Require all granted

Change AllowOverride None to All and save your changes.
Then, using the command, enable mode rewrite (In this case already enabled),

$ sudo a2enmod rewrite

The server should then be restarted.

$ sudo /etc/init.d/apache2 restart

Conclusion

You learned how to remove the public and index.php files in the new Codeigniter 4 framework in this article.
You can now go to the link below in your browser.

example.com/test

Quote of the day: live life

whatsapp callmobile call
×

Let's Talk 9795164872