Usually, in the CodeIgniter 4 project, you will see there is an additional argument in the URL. That is index.php in your project URL. So, if you don’t want this extra parameter then you can remove it. This will make a clean URL of your website. There are several ways to remove this index.php in CodeIgniter 4. You can create a .htaccess file and create the rule to override the URL. It will require the host to access the created .htaccess file. So, it depends upon the host like Apache or Nginx. In my last tutorial, I have shared the post on CodeIgniter 4 Multiple Image Upload. If you followed that then you have the idea of redirection of the URL with index.php after image upload. In this post, I am not going to create a new project in CodeIgniter 4 for this. I will be using an existing project here.
- To remove the index.php in CodeIgniter 4, you must have an installed project. You can create a new one if you don’t have.
I am not going to show you to create a project in CodeIgniter 4 here.
How to Check index.php in URL
Firstly, I have opened the project inside the VS Code editor. I already started my development server by hitting the spark command.
php spark serve
Now, you can see here, the development server is started on
Now, I am diverting you to the browser by following the above URL.
So, I already have the image upload functionality in my last post. Now, I have navigated to the specified route and I have the below screen.
Firstly, let me show you the impact of index.php before removing from the URL in CodeIgniter 4. Here, I have already the validation rule for validating image before upload. So, I chosen the valid image and clicked on the Upload button.
Here, the image is uploaded successfully. Now, you can see the URL has been redirected with index.php by default. The below URL is
Here, this is the impact of having the index.php in the URL. So, let’s remove it in the simple steps.
Remove index.php in CodeIgniter 4
Now, come back to the CodeIgniter 4 project. Firstly, go to the app/Config/App.php. You will see the baseURL of the project.
If you want to change the base url of the CodeIgniter 4 project then you can change it from here.
In the next line, you will see the Index File description. So, you already noticed one thing while accessing the homepage of the CodeIgniter. In the indexPage property by default the index.php was added.
Here, I haven’t changed the base URL. I will access it on the default port by running the applicaton through the spark command. So, I just removed the index.php from the indexPage.
CodeIgniter 4 project has by default .htaccess file in the public folder. So, no need to create another .htaccess file.
Now, go back to the homepage and refresh the URL. Here, I am trying to upload the image again. In the result, you can see the image is uploaded and the index.php is not showing in the URL.
Finally, we removed the index.php from the URL of CodeIgniter 4 application. Now, the URL became neat and clean. So, you can create routes and everything will work perfectly. I hope this tutorial will help you.