浏览器 URL 重定向到默认控制器时不会更改,Codeigniter

Browser URL not changing when redirect to default controller , Codeigniter

您好,我正在使用 codeigniter,当我在浏览器中输入我的基础 URL 时,我想重定向到默认控制器。

我的基地URL

http://localhost/itams/index.php

我的默认路线

$route['default_controller'] = "new_starter/listing";

我的问题是当我在浏览器中键入 http://localhost/itams/index.php 时,它正确地重定向到 new_starter/listing 页面,但浏览器 URL 没有改变。它显示为 http://localhost/itams/index.php.

Is that the default behavior ?

How can i change the Browser URL ?

Do i have to do a manual redirect using header() ?

提前致谢。

Is that the default behavior ?

答案。 -

How can i change the Browser URL ?

您需要将此代码放在 默认控制器方法的开头

    if($this->uri->total_segments() === 0){
        redirect('controller/method','refresh');
    }

在你的情况下listing new_starter 控制器的方法。

最终它应该看起来像这样

Class New_starter extends APP_Controller {
  ...
    public function listing(){
            if($this->uri->total_segments() === 0){
                redirect('new_starter/listing','refresh');
            }
           // rest of your method code.
    }
  ...
}