Automating the $baseURL
configuration value between test and production servers or when moving public/index.php
saves time and potential headaches. Follow this guide to define a DYNAMIC_BASE_URL
for use in your CodeIgniter 4 application.
Edit app/Config/Constants.php
<?php
/*
| --------------------------------------------------------------------
| Dynamic Base URL
| --------------------------------------------------------------------
|
| Generate absolute URL based on request scheme, host and script path.
*/
defined('DYNAMIC_BASE_URL') || define('DYNAMIC_BASE_URL', sprintf('%s://%s%s', (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost', str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME'])));
Continue reading