title: PHP MVC Application loosing path references to jss and css files
body: <p>I´m writing my own PHP MVC framework. So, the entry point for bootstrapping is at <code>myapp/public/index.php</code>.</p>
  
  <p>There I check the URL passed, as:</p>
  
  <pre><code>$url = $_GET["url"];
  </code></pre>
  
  <p>And then I explode the code finding the necessary controller, action and parameters to navigate:</p>
  
  <pre><code>    $parts = explode("/", trim($url, "/"));
  
      if (sizeof($parts) &gt; 0)
      {
          $controller = $parts[0];
  
          if (sizeof($parts) &gt;= 2)
          {
              $action = $parts[1];
              $parameters = array_slice($parts, 2);
          }
      }
  </code></pre>
  
  <p>From here the code loads and runs the controller and view.</p>
  
  <p>At the controller, I need (after successfull login) redirect to my app main page (called <code>main/index</code>). Here is the redirection code:</p>
  
  <pre><code>... controller code...
  $this-&gt;redirect("main", "index");
  ...
  </code></pre>
  
  <p>And</p>
  
  <pre><code>public static function redirect($controller, $method = "index", $args = array())
  {
      $location = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . $controller . "/" . $method . "/" . implode("/",$args);
  
      header("Location: " . $location);
      exit;
  }
  </code></pre>
  
  <p>Well, this calls again my <code>public/index.php</code>, but from now I loose all of my relative path referentes in the included javascript and css code, like:</p>
  
  <pre><code>&lt;link rel="stylesheet" rel="stylesheet" media="all" href="css/bootstrap.min.css"&gt;
  &lt;script type="text/javascript" charset="UTF-8" src="js/jquery-2.1.4.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Insted of looking at <code>myapp/public</code> it starts looking at <code>myapp/pubic/main/index</code> folder, where it natually does not belong to.</p>
  
  <p>Also, <code>myapp/public/main/index</code> is not even a valid folder (the controller and action is code is under <code>application/controllers</code> folder).</p>
  
  <p>I´m very confused in the way this mechanism of redirecting is working and I can´t find out the solution..</p>
  
  <p>My <code>.htaccess</code>, located in <code>myapp\public</code>:</p>
  
  <pre><code>Options -indexes
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^([a-zA-Z0-9\/\-_]+)\.?([a-zA-Z]+)?$ index.php?url=$1&amp;extension=$2 [QSA,L]
  </code></pre>
  
  <p>Thanks for helping....</p>