CodeIgniter Forums
Dynamic Base Url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Dynamic Base Url (/showthread.php?tid=22073)



Dynamic Base Url - El Forum - 08-28-2009

[eluser]Gregory Kornblum[/eluser]
Running into issues with the hard-coded method of setting the base url? Yeah, me too. So I made a wiki tips and tricks entry to help you simplify this setting.

http://codeigniter.com/wiki/Dynamic_Base_Url/


Dynamic Base Url - El Forum - 08-28-2009

[eluser]skunkbad[/eluser]
This seems to be a nice solution, but for me, my development server is set up with all of the websites as sub-directories of http://rbg72.web. I could probably configure my WAMP to run with name based virtual hosting or something, but for me there is something more simple. I have created a checklist for moving to another server. Because other things need to be changed, such as .htaccess and config.php, I always find myself configuring something.


Dynamic Base Url - El Forum - 08-29-2009

[eluser]WanWizard[/eluser]
In our CMS-to-be, base_url is defined as:
Code:
$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . ROOT;

The constant ROOT is defined in index.php, as:
Code:
define('ROOTPATH', realpath(dirname(__FILE__)) . '/');

// installed in the docroot?
if (realpath(dirname(__FILE__)) == $_SERVER['DOCUMENT_ROOT'])
{
    define('ROOT', '/');
}
else
{
    define('ROOT', substr(ROOTPATH, strlen($_SERVER['DOCUMENT_ROOT'])+1));
}

This will handle website installations in subdirectories of the DOCROOT.


Dynamic Base Url - El Forum - 09-07-2009

[eluser]Gregory Kornblum[/eluser]
Nice, your's is more thorough. That should be included in the framework's next release. What value does the hard-coding provide anyway?


Dynamic Base Url - El Forum - 09-07-2009

[eluser]Gregory Kornblum[/eluser]
I updated the wiki with your version and gave you credit. Thanks!