![]() |
anchor() with multiple subdomains/hostnames - 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: anchor() with multiple subdomains/hostnames (/showthread.php?tid=92695) |
anchor() with multiple subdomains/hostnames - rockinmusicgv - 03-31-2025 I'm using multiple subdomains and hostnames within an application. It looks like the anchor function uses the current URL to build the link element, however, it doesn't respect the current subdomain. So, while using a.example.com, the link will point to example.com domain. The current URL's host is the "example.com" domain, so from the anchor output, that's not unexpected, I suppose, but incorrect... RE: anchor() with multiple subdomains/hostnames - grimpirate - 04-02-2025 If you have sites on different subdomains each of them should have a distinct app.baseURL which you can set in your .env file. You may have taken a different approach, so all I could infer further would be perhaps to read the documentation for Managing your Applications. RE: anchor() with multiple subdomains/hostnames - rockinmusicgv - 04-02-2025 For now, everything is in one application. Some routes use the subdomain option in the route definition. I have the subdomain set in the .env file, and a helper to get the appropriate host to use. One thing is that it may be worthwhile to alter the anchor() helper to also accept URI objects, rather than just strings and arrays. But that might add complexity that's not worthwhile... RE: anchor() with multiple subdomains/hostnames - grimpirate - 04-02-2025 You can use an alternate configuration to achieve the same results (fourth optional parameter of the anchor function), and yes, the anchor function uses whatever is returned by the site_url function and appends segments to it. The anchor function will build external links successfully if you pass either http: or https: in the first segment. So however you're tracking/detecting your domains, prepend them to the first parameter and you should achieve what you want. RE: anchor() with multiple subdomains/hostnames - InsiteFX - 04-02-2025 PHP Code: public 'allowedHostnames' -> array (0) [] |