【发布时间】: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