简体   繁体   中英

Overloading CodeIgniter's base_url

I have 54 sites that have different URLS but use the exact same codeigniter system AND application folders (before you think I spam for a living, the reality is that we own/manage 54 properties that use the same website 'template' and differentiate content for each via the database and/or separate asset folders in the vhosts/httpdocs folders.)

I placed the system and application folders for CI_2.0.3 in the vhosts directory above the httpdocs folder for each domain and can hit it successfully from two test sites with each showing the CI Welcome screen.

However, I am concerned about the base URL. If one is www.campuslodge.com and another is campuscreek.com, how do I handle that in a single config/config.php file? I can pass the property number to the application via the index.php file that exists in each of the 54 domain httpdocs folders, so can I also declare a global there for base_url and leave the one in config/config.php blank??? Or should I do something else???

Bottom line is that I need 54 unique domains to point to a single CI installation of both system and application so that I can make global changes once rather than 54 times.

In your config file, you can leave the $config['base_url'] set to an empty string and codeigniter will guess what the correct protocol and domain is. So, if a client accesses your site at http://www.example.com/controller/method/arg.html , then base_url() will return http://www.example.com/

Otherwise, you can set it to $_SERVER['SERVER_NAME'] and it will be set to whatever the domain was that was accessed by the client.

// in application/config.php
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'];

you answered your question. Define a constant in each index.php, say:

define('_MY_BASE_URL', 'http://yourdoamin.com');

and in the config.php do:

$config['base_url'] = _MY_BASE_URL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM