【问题标题】:Browser URL not changing when redirect to default controller , Codeigniter重定向到默认控制器,Codeigniter 时浏览器 URL 不变
【发布时间】:2015-01-19 08:36:43
【问题描述】:

您好,我正在使用 codeigniter,当我在浏览器中键入我的基本 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。

这是默认行为吗?

如何更改浏览器 URL?

我必须使用header() 进行手动重定向吗?

提前致谢。

【问题讨论】:

  • 更改基本网址?
  • @RakeshSharma 对不起,我没有明白你的意思,你能解释一下吗:)
  • 它应该在默认控制器上重定向。你有路由吗?也从 url 中删除 index.php
  • @RakeshSharma 默认控制器是 'new_starter/listing' ,它正在重定向到默认控制器,但浏览器 URL 停留在 'localhost/itams/index.php' ,我认为我有点误导。
  • 不,我没有。 URL重定向和'index.php'有什么联系吗?

标签: php .htaccess codeigniter redirect


【解决方案1】:

这是默认行为吗?

回答。 - 是

如何更改浏览器 URL?

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

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

即在你的情况下是listingnew_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.
    }
  ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    相关资源
    最近更新 更多