I want to direct mydomain.com to m.mydomain.com if the user opens the website via mobile. I use mobiledetect.net and I have installed it using a composer. when I try to open a website via my mobile I get an error notification "ERR_TOO_MANY_REDIRECTS".
This my controller :
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;
}
}
}
how can I fix this error?
I only use the default htaccess from the CI documentation
HTACCESS
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]