CodeIgniter 4 projects, you’ll notice that the URL has an extra argument. It is index.php in your project URL. So, if you don’t want this extra dimension you can remove it. This will create a clean URL for your website. There are several ways to remove this index.php in CodeIgniter 4. You can create a .htaccess file and create a rule to override URLs. It will require a host to access the .htaccess file it creates. So, it depends on a host like Apache or Nginx.
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 one.
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, that the development server is started on http//localhost:8080
.
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 CodeIgniter. In the index page property by default, the index.php was added.
Config/App.php in CodeIgniter 4
Here, I haven’t changed the base URL. I will access it on the default port by running the application through the spark command. So, I just removed the index.php from the index page.
Removed index.php From the Config in CodeIgniter 4
CodeIgniter 4 project has by default a .htaccess file in the public folder. So, no need to create another .htaccess file.
.htaccess file in CodeIgniter 4
Now, index.php is Removed From URL in CodeIgniter 4
Conclusion
Finally, we removed the index.php from the URL of the 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.
Great article. Thanks!
Thanks & Good Codeigniter information provide.
“Great content as always! Thanks a lot.”
“This is what exactly I was looking for🙏
Thanks a lot buddy for sharing.,its really easy to understand and implement.”
Very detailed explanation. Thanks for sharing it.