title: How to redirect mydomain.com to m.mydomain.com with mobiledetect.net in codeigniter?
body: <p>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".</p>
  
  <p>This my controller :</p>
  
  <pre><code>class Welcome extends CI_Controller {
  
      public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;helper('url');
      }
  
      public function index()
      {
          $detect = new Mobile_Detect;
          if($detect-&gt;isMobile()) {
              header("location: http://m.mydomain.com");
              exit;
          }
      }
  }
  </code></pre>
  
  <p>how can I fix this error?</p>
  
  <p>I only use the default htaccess from the CI documentation</p>
  
  <p>HTACCESS</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
  </code></pre>