Banner Blog Search Intent C 1024x576 Mitra IT | Your Trusted & Reliable Software Solutions

Codeigniter : Dynamic

Base URL Configuration

is still being hotly discussed at this time. In this version 4 update, there are changes that can be said to be very significant compared to the previous version, namely version 3.x. In addition, tutorials in Indonesian are still very rare.

In this post, I will share how to dynamically configure base_url().

This dynamic base_url() configuration is useful when you publish a website project to hosting or when you change the folder name of the project you are working on with Codeigniter 4.x.

Where you don’t need to specify or configure again.

What can this script do?

  1. Automatically determine the base_url() of a web project created with Codeigniter 4.
  2. Detect web protocols, whether http or https, this works when you direct or redirect to a certain protocol. With this, calling assets such as css, js, and images will not experience errors or get warnings from the browser.
  3. Minimize configuration when uploading to hosting or when changing the folder name of the project.

How to implement it?

To implement it, you need to open two files in the Config directory/folder, namely:

  1. App.php (/app/Config/App.php)
  2. Constants.php (/app/Config/Constants.php)

The first thing to do is to create a code that functions to determine the project URL in the Constants.php file. The method is to add the following script at the bottom line

After determining the project URL, then call the function above in the App.php file by changing the $baseUrl value to BASE.

That’s the tutorial for dynamically configuring the base URL in Codeigniter 4.x. Hopefully this article can help you.

Why choose Mitra IT?

•⁠ ⁠Expert Team: We have a team of experienced and creative technology experts.

•⁠ ⁠Comprehensive Solutions: We not only provide technology but also offer full support to ensure your business success.

•⁠ ⁠Focused on Results: We are committed to helping you achieve your business goals.

Don’t miss the opportunity to maximize your business potential!

Contact us now for a free consultation.