title: CodeIgniter: URL structure based on folders and sub-folders
body: <p>I'm having a bit of an issue with the current CodeIgniter. I have a CI install with a "Pages" controller that loads static files from /views, but it only goes up to 1 sub-folder and I'm looking to add another sub-folder to it.</p>
  
  <p>Pretty much it does the following:</p>
  
  <ol>
  <li>If the URL segment requested (e.g. site.com/url) is in /views as a file (e.g. /views/url.php) it would load it from there, but if the URL segment (e.g. url) is actually a folder inside /views it would load index.php from that folder (e.g. /views/url/index.php while the URL is still site.com/url).</li>
  <li>The above goes with any other name of files and not only index.php. If I have site.com/url/buy, it would load the buy.php file from the /views/url folder.</li>
  </ol>
  
  <p>What I'm trying to achieve is to add a new sub-folder to this structure:</p>
  
  <ol>
  <li>If I go on site.com/url/buy/faq to load the faq.php file from /views/url/buy and so on..</li>
  </ol>
  
  <p>The current Pages.php controller is the following:</p>
  
  <pre><code>class Pages extends CI_Controller {
  
  public function view($page = 'index', $sub_page = 'index') {
  
      if ($page == 'index') {
          $path = $page . '.php';
      } else {
          $path = $page . '/' . $sub_page . '.php';
      }       
  
      if (!file_exists('application/views/pages/' . $path)) {
          if (!file_exists('application/views/pages/' . $page . '.php')) {
              show_404();
          } else {
              $path = $page . '.php';
          }
      }
  
      // $this-&gt;output-&gt;cache(60);
      // $this-&gt;output-&gt;enable_profiler(TRUE);
  
      $data['title'] = ucfirst($page);
      $data['url'] = lcfirst($page);
  
      $this-&gt;load-&gt;view('pages/modules/header', $data);
      $this-&gt;load-&gt;view('pages/'. $path, $data);
      $this-&gt;load-&gt;view('pages/modules/footer', $data);
  
  }
  }
  </code></pre>
  
  <p>Do you guys have any suggestions?</p>
  
  <p>Thanks in advance!</p>