Today, we will learn how to remove index.php from URL in Codeigniter 4. why are you remove index.php from URL? because when users using create SEO friendly, user readability and easy to understand for the user.
Now, let’s start to discuss how to remove index.php from URL in Codeigniter 4. so you can follow the below step.
Step 1: Update in the App.php File
In this step, We need to change baseURL, indexPage and uriProtocol in the “config/app.php” file. so you can follow the below changes.
//change the baseUrl
public $baseURL = 'http://localhost:8080';
public $baseURL = 'http://localhost/your_project_name/';
//remove the index.php from indexPage
public $indexPage = '';
//change the uriProtocol
public $uriProtocol = 'REQUEST_URI';
public $uriProtocol = 'PATH_INFO';
Step 2: Copy index.php and .htaccess files
The second step Copy the “index.php” and “.htaccess” files file in the public directory and paste on root your project directory.
Step 3: Update In the index.php
Finally, after move successfully files on the root directory. The open “index.php” file and change the pathsPath.
$pathsPath = FCPATH . '../app/Config/Paths.php';
$pathsPath = FCPATH . 'app/Config/Paths.php';