繁体   English   中英

如何在sourceigniter中从根URL重定向到控制器?

[英]How to redirect from root URL to controller in codeigniter?

我在以下URL下有主视图:

 http://wifi.pocc.cnst.com/cnst/#/mapboard/
 |     root               |cntrl|  view   |       

我的目标是当用户在浏览器中输入时: http://wifi.pocc.cnst.comhttp://wifi.pocc.cnst.com/cnst/#/mapboard/自动重定向到http://wifi.pocc.cnst.com/cnst/#/mapboard/

我怎样才能做到这一点?

谢谢,

您可能知道请求到控制器的映射是

http://your.domain/index.php/controller/method/arg1/../argn

而没有给出controller/method/args段的任何请求都被路由到默认控制器。

默认控制器在application/config/routes.php定义,您必须按如下方式更改它:

$route['default_controller'] = "my_default_controller";

其中my_default_controller显然是您必须设置的控制器,其中您设置:

public function index()
{

    $this->load->helper('url'); // might actually not be needed
    redirect('cnst/#/mapboard');
}

如果您使用默认控制器进行其他操作,您可以考虑:

public function index()
{
    if ($this->input->server('Request_uri') == '/' and $this->input->server('Http_host') == 'my-host')
    {
        $this->load->helper('url'); // might actually not be needed
        redirect('cnst/#/mapboard');
    }
    // your other stuff
}

或者您可能实际在routes.php配置文件中设置了不同的默认控制器:

if ($_SERVER['REQUEST_URI']) == '/' and isset($_SERVER['HTTP_HOST']) and $_SERVER['HTTP_HOST'] == 'my-host')
{
    $route['default_controller'] = 'my_special_controller';
}
else
{
    $route['default_controller'] = 'my_normal_controller';
}

瞧。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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