【问题标题】:First visit to codeigniter site is redirected to root首次访问 codeigniter 站点被重定向到 root
【发布时间】:2019-07-30 12:43:49
【问题描述】:

我已经使用 CodeIgniter 继承了一个代码库。

当第一次查看网站时,所有页面都被重定向到主页。之后,网站正常运行。

如果我在 codeigniter 之外创建一个“真实页面”,则没有重定向。这排除了 htaccess 问题。

routes.php 包含:

defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Home';
$route['404_override'] = 'Error_new';
$route['translate_uri_dashes'] = FALSE;

控制器 Homes.php

defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('pagination_helper');
        no_cache();
        $this->load->helper(array('form'));
        $this->load->helper(array('cookie', 'url'));
        $this->load->model('home_model');
    }

    public function index()
    {
        /*redirect(base_url().'booking');*/
        $this->load->library('Mobile_Detect');
        $detect = new Mobile_Detect();

        if ($detect->isTablet()) {
             //$this->home_model->insert_city_in_tbl();
            $template['page'] = 'Home/home';
           $template['page_title'] = "xxxxx";
            $this->load->view('template', $template);

        } 

       else if ($detect->isMobile()  || $detect->isAndroidOS()) {
             redirect('https://m.xxxx.com/');


        } else {

            //$this->home_model->insert_city_in_tbl();
            $template['page'] = 'Home/home';
            $template['logo'] = get_settings_details(1, null);
            $template['country'] = get_settings_details(null, 'country');
            $template['popular_routes']=$this->home_model->getPopularRoutes();
            $template['page_title'] = "XXXXXXX";
            $this->load->view('template', $template);
        }
    }

有没有人指点一下如何解决这个问题?

【问题讨论】:

  • 如果我不得不猜测,我会说您的移动检测逻辑有问题。在移动检测后,您似乎将几乎每个人都定向到home/home。 (例外是那些被重定向到m.example.com 的人,因为他们被标记为移动设备或安卓
  • 不是这样,因为重定向发生在调用索引函数之前。另外,这并不能解释第一次来访者的原因
  • 它可能会。因为您的默认控制器是home,所以首先调用的是home/index,它运行移动检测例程。在没有看到该代码的情况下,只能猜测,但可能会涉及一些 cookie,以防止非第一个计时器被重新验证和重定向。
  • 但话又说回来,我只是在猜测。我不知道您正在使用的库,并且在我的手机上查找它是我能做的最不可读的事情......您尝试过什么调试?

标签: php .htaccess codeigniter


【解决方案1】:

更改您的实时 config.php 文件

$config['base_url'] = 'http://www.yoursite.com

Source

【讨论】:

    【解决方案2】:

    解决方案是使用一些 cookie 逻辑将客户重定向到主页。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      相关资源
      最近更新 更多