【问题标题】:one codeigniter controller named site needs to handle multiple domains一个名为 site 的 codeigniter 控制器需要处理多个域
【发布时间】:2012-06-24 04:39:37
【问题描述】:

在 codeigniter 中有一个控制器来处理不同的子站点。

  • site/index/1 获取子站点 A 的内容

  • site/index/2 获取子站点 B 的内容

现在我们决定为这些子站点注册域名。

所以我们需要:

http://www.subsite1.com  -> default controller should be site/index/1

URI 中没有site/index/1

http://www.subsite2.com  -> default controller should be site/index/2

URI 中没有site/index/2

我摆弄并尝试与routes.php 一起玩,但无济于事.. 有人能指出我正确的方向吗?

【问题讨论】:

    标签: codeigniter routes multiple-domains


    【解决方案1】:

    在你的 routes.php 文件中你需要设置这个:

    $route['default_controller'] = ($_SERVER['SERVER_NAME'] == 'http://www.subsite1.com' ? "site/index/1" : "site/index/2");
    

    如果你在输入一些奇怪的 url 时试图在某个地方强制它:

    $route['404_override'] = ($_SERVER['SERVER_NAME'] == 'http://www.subsite1.com' ? "site/index/1" : "site/index/2");
    

    第二个只需切换到 2

    【讨论】:

    • 带有 switch 语句?像开关 ($_SERVER['HTTP_HOST']){
    • 如果您尝试像那样切换它,我只会使用简写 if 语句。或者只是使用常规 if 语句,将结果设置为变量,然后分配变量。查看我的编辑。
    猜你喜欢
    • 2011-06-12
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2015-09-18
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多