重载CodeIgniter的base_url
我有 54 个网站,它们具有不同的 URL,但使用完全相同的 codeigniter 系统和应用程序文件夹(在您认为我以垃圾邮件为生之前,现实是我们拥有/管理 54 个使用相同网站“模板”并区分内容的属性)每个域都通过 vhosts/httpdocs 文件夹中的数据库和/或单独的资产文件夹。)
我将 CI_2.0.3 的系统和应用程序文件夹放置在每个域的 httpdocs 文件夹上方的 vhosts 目录中,并且可以成功命中它来自两个测试站点,每个测试站点都显示 CI 欢迎屏幕。
但是,我担心基本 URL。如果一个是 www.campuslodge.com,另一个是 Campuscreek.com,我如何在单个 config/config.php 文件中处理它?我可以通过 54 个域 httpdocs 文件夹中每个文件夹中存在的 index.php 文件将属性号传递给应用程序,所以我也可以在那里为 base_url 声明一个全局并将 config/config.php 中的保留为空吗???或者我应该做点别的事???
最重要的是,我需要 54 个唯一的域来指向系统和应用程序的单个 CI 安装,以便我可以进行一次全局更改,而不是 54 次。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在配置文件中,您可以将
$config['base_url']
设置为空字符串,codeigniter 会猜测正确的协议和域是什么。因此,如果客户端通过 http://www.example.com/controller/ 访问您的网站method/arg.html,则base_url()
将返回http://www.example.com/
否则,您可以将其设置为
$_SERVER['SERVER_NAME']
它将设置为客户端访问的任何域。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, thenbase_url()
will returnhttp://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.你回答了你的问题。在每个 index.php 中定义一个常量,例如:
在 config.php 中执行以下操作:
you answered your question. Define a constant in each index.php, say:
and in the config.php do: