[英]How to remove the controller name from url in codeigniter, and still be able to redirect on another controller?
[英]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.com
: http://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.