Remove public/index.php/ from url in codeigniter 4. In this tutorial, i will show you in detail on how to remove public and index.php from URL in Codeigniter 4 framework.
When you download and setup codeigniter 4 application on your system and server. Then in the new codeigniter 4 application the urls with public/index.php remain bydeault.
You want to keep the urls of your codeigniter 4 application pretty and clean. Or you can say that you want to keep the urls seo-friendly.
So in this tutorial I will teach you how you can remove public /index.php in codeigniter 4 application. You can make end urls seo-friendly.
How to remove public/index.php/ from URL in Codeigniter 4
You follow the steps given below to remove public/index.php/ from url in codeigniter 4 apps:
Step 1 – Install Codeigniter 4 App
If you do not know how to install and setup Codeigniter 4. So you can learn this here.
Codeigniter 4 Install / Download using Composer or Manually
Step 2 – Change in App.php File
Now, you need to open app.app file. And the changes mentioned given below.
So, visit codeigniter_4_app/app/Config/App.php and change mention below:
public $baseURL = 'http://localhost:8080'; To public $baseURL = 'http://localhost/your_project_name/';
And the second change in the app.php file:
public $uriProtocol = 'REQUEST_URI'; To public $uriProtocol = 'PATH_INFO';
Step 3 – Copy index.php and .htaccess
Visit inside public directory. And copy index.php and .htaccess to codeigniter 4 app root directory.
Step 4 – Change In index.php
After that, you need to visit root project directory, open index.php and modify the following line of code:
$pathsPath = FCPATH . '../app/Config/Paths.php'; change TO $pathsPath = FCPATH . 'app/Config/Paths.php';
How to remove public/index.php/ from url in codeigniter 4. In this tutorial, you have learned how to remove public and index.php from URL in Codeigniter 4 framework.
Now open your browser and hit any url of your codeigniter 4 app. Then you will see that your codeigniter 4 app has been removed from public /index.php.