簡體   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