![]() |
Dynamic $baseURL for multiple hosts - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Dynamic $baseURL for multiple hosts (/showthread.php?tid=77398) |
Dynamic $baseURL for multiple hosts - muncherelli - 08-26-2020 I am developing an app that will have multiple domains and subdomains pointed at it. I would like to have CodeIgniter automatically detect the Base URL. In Config/App.php it says this: PHP Code: /* I also have this line commented out in my .env file: Code: # app.baseURL = '' I am receiving this error: You have an empty or invalid base URL. The baseURL value must be set in Config\App.php, or through the .env file. How can I dynamically set the Base Site URL to use for multiple sites pointing to the app? RE: Dynamic $baseURL for multiple hosts - LynxCoder - 08-27-2020 (08-26-2020, 08:04 PM)muncherelli Wrote: I am developing an app that will have multiple domains and subdomains pointed at it. I would like to have CodeIgniter automatically detect the Base URL. My baseURL is set in the .ENV file, which if I remember rightly, takes precedence - worth checking that in the project root folder. RE: Dynamic $baseURL for multiple hosts - pippuccio76 - 08-27-2020 (08-26-2020, 08:04 PM)muncherelli Wrote: I am developing an app that will have multiple domains and subdomains pointed at it. I would like to have CodeIgniter automatically detect the Base URL.in config->App.php you must do some like this : PHP Code: class App extends BaseConfig RE: Dynamic $baseURL for multiple hosts - Chroma - 08-27-2020 PHP Code: |-------------------------------------------------------------------------- I don't know if that function helps, but it enables me to use the same code for development, preview and production. In CI4, I place it at the end of the App.php file in the Config folder. I had a similar system with CI3, which was a little easier, but this seems to work nicely and isn't too expensive to run in terms of time. I hope this is useful. Don't forget, you might want to force HTTPS on the production server, but this code makes it easy for both development and production. RE: Dynamic $baseURL for multiple hosts - John_Betong-002 - 08-27-2020 'because index.php is always the first file encountered when browsing I define a constant which is passed to ./app/Config/App.php https://github.com/John-Betong/ci4-strict.tk/blob/master/public_html/index.php The script was opied from a user on this forum and isI used it on numerous projects. Tentatively tapped on a tablet ![]() |