Dynamic $baseURL for multiple hosts |
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? (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.
(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 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.
'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-stric.../index.php The script was opied from a user on this forum and isI used it on numerous projects. Tentatively tapped on a tablet |
Welcome Guest, Not a member yet? Register Sign In |