How to redirect from root URL to controller in codeigniter?

I have a basic view at the following URL:

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

My goal is when the user types in the browser: http://wifi.pocc.cnst.comto automatically redirect tohttp://wifi.pocc.cnst.com/cnst/#/mapboard/

How can i achieve this?

Thanks,

+4
source share
1 answer

As you know, displaying requests to controllers is

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

whereas any request for which segments are specified controller/method/argsis routed to the controller by default.

The default controller is defined in application/config/routes.php, and you will need to change it as follows:

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

where my_default_controller, obviously, is the controller that you have to configure, and in it you install:

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

.

+3

Source: https://habr.com/ru/post/1526570/


All Articles