Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用codeigniter中的mobiledetect.net将mydomain.com重定向到m.mydomain.com?_Php_Codeigniter - Fatal编程技术网

Php 如何使用codeigniter中的mobiledetect.net将mydomain.com重定向到m.mydomain.com?

Php 如何使用codeigniter中的mobiledetect.net将mydomain.com重定向到m.mydomain.com?,php,codeigniter,Php,Codeigniter,如果用户通过手机打开网站,我想将mydomain.com指向m.mydomain.com。我使用mobiledetect.net,并使用composer安装了它。当我试图通过手机打开一个网站时,我收到一个错误通知“ERR\u TOO\u MANY\u REDIRECTS” 这是我的控制器: class Welcome extends CI_Controller { public function __construct() { parent::__constru

如果用户通过手机打开网站,我想将mydomain.com指向m.mydomain.com。我使用mobiledetect.net,并使用composer安装了它。当我试图通过手机打开一个网站时,我收到一个错误通知“ERR\u TOO\u MANY\u REDIRECTS”

这是我的控制器:

class Welcome extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }

    public function index()
    {
        $detect = new Mobile_Detect;
        if($detect->isMobile()) {
            header("location: http://m.mydomain.com");
            exit;
        }
    }
}
如何修复此错误


我只使用CI文档中的默认htaccess

HTACCESS

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

使用移动站点时,需要排除对移动设备的检测。您可以这样实现:

public function index()
{
    $host='http://'.$_SERVER["HTTP_HOST"];
    $detect = new Mobile_Detect;
    if($detect->isMobile() && $host!='http://m.mydomain.com') {
        header("location: http://m.mydomain.com");
        exit;
    }
}

请显示您的.htaccess或windows等效版本。我仅使用CI文档中的默认htaccess。但在直接访问m.mydomain.com之前,错误消息仍会在几秒钟内出现。不直接发送到m.mydomain.com这可能是缓存问题,请尝试使用其他移动浏览器或其他电话。我已使用不同的设备尝试并删除了浏览器缓存,但仍然如此。我添加了
'http://'
以生成$host变量。现在,它应该在第一次尝试匹配。在寻找匹配m.mydomain.com之前,它没有找到匹配的m.mydomain.com(因此出现错误),然后重定向到
http://m.mydomain.com
和匹配项。现在它应该排在第一位。请确认。这个工作:)你能告诉我,如何让这个脚本在所有控制器上运行??