How to remove index.php and public in codeigniter 4
In this article we are going to learn how to remove index.php and public in codeigniter 4. But question arise why we will do so. We will do it for the SEO friendly url so that more user readability and better rank in search engine.
Now follow below steps to remove index.php and public in Codeigniter 4.
Step- 1 : Modify App.php file
First step is to open App.php file which is located in “your_project_name/app/Config/App.php” and made below changes.
//modify the baseUrl public $baseURL = 'http://localhost:8080'; To public $baseURL = 'http://localhost/your_project_name/'; //modify the index.php from indexPage public $indexPage = ''; //modify the uriProtocol public $uriProtocol = 'REQUEST_URI'; To public $uriProtocol = 'PATH_INFO'; //
Step -2 : Copy index.php and .htaccess files
Second step is to go to public directory and copy index.php and .htaccess file and paste it into your project’s root directory.
Step – 3 : Modify index.php file
After coping index.php and .htaccess file in project’s root directory , open index.php file and modify like below :
$pathsPath = FCPATH . '../app/Config/Paths.php'; change TO $pathsPath = FCPATH . 'app/Config/Paths.php';