title: Redirect too many times! Codeigniter
body: <p>In a Multilingual website the URLs look like this <code>http://localhost/mysite/en/about</code>. This works fine upto single level of URL redirection.</p>
  
  <p>But when i try to make these URLs SEO friendly <code>http://localhost/mysite/en/about/about-childs</code>, it redirects to same page too many times and never comes on destination. I am unable to find the cause. </p>
  
  <p>I am using <code>redirect($slug-&gt;language_slug.'/about/about-childs','refresh');</code></p>
  
  <p>And here is the redirect helper function </p>
  
  <pre><code>function redirect($uri = '', $method = 'auto', $code = NULL)
  {
      if ( ! preg_match('#^(\w+:)?//#i', $uri))
      {
          $uri = site_url($uri);
      }
  
      // IIS environment likely? Use 'refresh' for better compatibility
      if ($method === 'auto' &amp;&amp; isset($_SERVER['SERVER_SOFTWARE']) &amp;&amp; strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
      {
          $method = 'refresh';
      }
      elseif ($method !== 'refresh' &amp;&amp; (empty($code) OR ! is_numeric($code)))
      {
          if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) &amp;&amp; $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
          {
              $code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
                  ? 303   // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
                  : 307;
          }
          else
          {
              $code = 302;
          }
      }
  
      switch ($method)
      {
          case 'refresh':
              header('Refresh:0;url='.$uri);
              break;
          default:
              header('Location: '.$uri, TRUE, $code);
              break;
      }
      exit;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is my <strong>routs.php</strong> file code, and it comes into else part where it returns controller function <code>return 'findcontent/index';</code> which contains my redirect functionality <code>redirect($slug-&gt;language_slug.'/about/about-childs','refresh');</code> </p>
  
  <pre><code>    $route['^(\w{2})/(.*)'] = function($language, $link) use ($controllers_methods)
  {
      if(array_key_exists($language,$controllers_methods))
      {
          foreach ($controllers_methods[$language] as $key =&gt; $sym_link) {
              if (strrpos($link, $key, 0) !== FALSE) {
                  $new_link = ltrim($link, $key);
                  $new_link = $sym_link . $new_link;
                  return $new_link;
              }
              else
              {
                  return 'findcontent/index';
              }
          }
      }
      else
      {
          return $link;
      }
  };
  $route['^(\w{2})$'] = $route['default_controller'];
  </code></pre>
  
  <p>Here is <strong>htaccess</strong> </p>
  
  <pre><code>RewriteEngine On
  SetEnvIf Host www.yoursite.tld$ CI_ENV=production
  #SetEnvIf Host test.yoursite.tld$ CI_ENV=testing
  SetEnvIf Host localhost$ CI_ENV=development
  
  RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
  </code></pre>