gpt4 book ai didi

php - 如何在 codeigniter 中从根 URL 重定向到 Controller ?

转载 作者:可可西里 更新时间:2023-10-31 23:05:44 24 4
gpt4 key购买 nike

我在以下 URL 下有主视图:

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

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

我怎样才能做到这一点?

谢谢,

最佳答案

你可能知道请求到 Controller 的映射是

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

而任何未提供 controller/method/args 段的请求都会被路由到默认 Controller 。

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

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

my_default_controller 显然是您必须设置的 Controller ,您可以在其中设置:

public function index()
{

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

如果您也将默认 Controller 用于其他用途,您可能会考虑:

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 配置文件中设置不同的默认 Controller :

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';
}

瞧。

关于php - 如何在 codeigniter 中从根 URL 重定向到 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21733090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com